0
votes

I have jqwidget grid that i am using to manage an entity named "QuestionCategory"; I have an observableArray moduleQuestions that holds all the entity properties. when i want to push the fetched entity from the server or new created entity from the client into moduleQuestions which is the source of my grid, i do have an exception saying TypeError: Converting circular structure to JSON. But, when i delete the entityAspect of the entity, i have a successful push to my observableArray. Here is the method to add new enity.

    createQuestionModule(data, observableModule: KnockoutObservableArray, moduleEntityAspect:KnockoutObservableArray){
    //data object
    //observableModule :moduleQuestions KnockoutObservableArray
//moduleEntityAspect an observableArray to keep track of each entity's entityAspect
                var newQuestionModuleType :any= this.manager.metadataStore.getEntityType("QuestionCategory");
                var newQuestionModule = newQuestionModuleType.createEntity(data);
                var mapper = this.manager.addEntity(newQuestionModule);
                moduleEntityAspect.push(mapper.entityAspect);//obervableArray to hold annoying entityAspect before deleting it
                 delete mapper.entityAspect;
                observableModule.push(mapper);
                observableModule.valueHasMutated();


        }

so i do delete the entityAspect before pushing the entity to my observableArray and i have a successful grid being displayed. here is the knockout binding that produces the grid:

 <div data-bind="jqxGrid: {
    source: moduleQuestions,
    autoheight: true,

    //rendertoolbar : '',
    theme: 'bootstrap',
    editable: true,
    selectionmode: 'singlecell',
    altrows:true,
    sortable: true,
    enabletooltips:true,
    pageable: true,
    autoheight: true,
    showemptyrow: false,
    autosavestate:true,
    columns: [

         { text: 'Module Name', dataField: 'CategoryName', width: 100, cellsalign:'center', validation: moduleNameValidation, cellendedit:celledited },
         { text: 'Description', dataField: 'Description', width: 200, cellsalign: 'center', cellendedit: celledited },
         { text: 'Status', dataField: 'IsEnable', width: 100, columntype: 'checkbox', cellsalign: 'center', cellendedit: celledited },
         { text: 'Action', dataField: 'QuestionCategoryID', cellsrenderer: AddSubjectRender, editable: false, cellsalign: 'center', cellendedit: celledited }

    ]}" id="questionModuleGrid">

there is a cellendedit in the column array that calls a particular function celledited with five parameters being passed to it during the calls whenever any cell in the grid is edited. this happens whenever the cell in the grid is updated. Here is the celledited function:

 celledited = (row, datafield, columntype, oldvalue, newvalue) => {
        //row is the row index
        //datafield is an entity property from breeze
        // columntype is a type of column which can be checkbox,textbox etc 
        //oldvalue is the original value before being changed
        //newvalue is the _latestValue
        if (oldvalue != newvalue) {
            var breezeEntityinGrid = QuestionCategory.moduleQuestions()[row];// this gives us the whole row that is being edited form observableArray =>moduleQuestions
            var entityAspect = QuestionCategory.moduleEntityAspect()[row];// get the entityAspect of the enity.

            breezeEntityinGrid["entityAspect"] = entityAspect; // to add the entityAspect back to the entity


            //then, this produces exception when updating the particular entity property ()=>TypeError: Converting circular structure to JSON
            breezeEntityinGrid[datafield](newvalue); //so  i commented this out then,  try the following method




            breezeEntityinGrid.Description._latestValue = newvalue; //the property to be updated
            var newQuestionModuleType = this.manager.metadataStore.getEntityType("QuestionCategory");

            this.manager.attachEntity(breezeEntityinGrid, breeze.EntityState.Modified);//yet the manager is not aware of that

            delete breezeEntityinGrid["entityAspect"];//to remove it from the entity

            return true;

        }
    }

I am confuse. I want to use the grid and also set the property of my entity when they change, so that when calling saveChages, the updated value can be saved, but committing it to the breeze manager, there is problem. please i need help.

1

1 Answers

0
votes

Not entirely sure what you are trying to accomplish but removing the entityAspect for an entity is a really bad idea. Breeze depends heavily on this. In general there are other ways of removing circularity depending on the grid in question. I would talk to the grid vendor and discuss this with them.