How to edit OndemandGrid and update to the JSONRest Store

1.2k views Asked by At

The JsonRest store I created is shown below

var questionBaseURL = "/" + contextName + "/service/questions/" + projectId + "/";
var questionStore = new dojo.store.JsonRest({
    target: questionBaseURL,
    handleAs: 'json',
    idProperty: 'questionId'
});

questionStore = new dojo.store.Observable(questionStore);
var memoryStore = new dojo.store.Memory();
var questionCacheStore = new dojo.store.Cache(questionStore, memoryStore);

Which I use to render into the Grid created as below

var CustomGrid = declare([OnDemandGrid, Keyboard, Selection]);
var questionGrid = new CustomGrid({
    store: questionCacheStore,
    columns: [
        editor({
            label: "Questions",
            field: "question",
            editor: "text",
            editOn: "dblclick",
            sortable: true,
            autoSave:true
        })
    ],
    selectionMode: "single",
    cellNavigation: false
}, "questions");
questionGrid.startup();
questionGrid.renderArray(questionArray);

The data is properly populated in the grid. Now, since am using "editor", I am able edit the populated data in the grid. I am not sure how exactly to detect if the data has been edited (dirty data ) and which method to call to carry the updated data back to the server. I couldn't find any easy documentation. So any help is appreciated. Thanks in advance

1

There are 1 answers

2
Ken Franqueiro On

You can use the grid's save method to push all items with dirty data back to the server. There is also a revert method which can be called to discard any dirty data. These are listed in the OnDemandList and OnDemandGrid documentation.

These methods are defined in dgrid/_StoreMixin which is inherited by OnDemandList (and OnDemandGrid). The editor column plugin calls updateDirty (also defined by _StoreMixin) when changes are made, which updates a dirty hash. save will check this hash and call put on the store for each dirty item.