Dojo Version is 1.7.2
I have a DataGrid which is filled with data from a MemoryStore. It works fine but the data in the grid is not updated when objects are updated in the store.
this is how the grid and the store are connected:
formStore = Observable(new MemStore());
formGrid = new DataGrid( {
store:ObjectStore( {objectStore:formStore} ),
query:{id:"*"},
structure:[
{ name:" ", field:"pending", width:"2em",
formatter:function ( count, rowIdx, cell ) {
return '<div style="font-size: smaller; text-align: right;">' + count + '</div>';
}
},
{ name:" ", field:"name", width:"auto",
formatter:function ( formName, rowIdx, cell ) {
return '<div style="white-space: nowrap;">' + formName + '</div>';
}
}
]
}, "formGrid" );
and I have a function which updates data in the store:
function updateForms() {
require( ["dojo/_base/xhr", "dojo/_base/array", "dojox/grid/DataSelection"],
function ( xhr, array, DataSelection ) {
xhr.get( {
url:"services/jsonrest/form/",
content:{ id:"all" },
handleAs:"json",
load:function ( forms, io ) {
array.forEach( forms, function( form, idx ) {
formStore.notify(form, form.id);
});
}
} );
} );
}
if the store is empty when this function runs, the items will be shown in the DataGrid
but once the items are in the grid they don't get updated. This is a test system, part of the Form object changes on every call.
What I ended up doing is change the method on the server to return all the items all the time and then the javascript function is like so:
function updateForms() {
require( ["dojo/_base/xhr", "dojo/_base/array", "dojox/grid/DataSelection"],
function ( xhr, array, DataSelection ) {
xhr.get( {
url:"services/jsonrest/form/",
content:{ id:"all" },
handleAs:"json",
load:function ( forms, io ) {
// reset all the items in the DataGrid
formGrid.setItems( forms );
}
} );
} );
}
this works as well. The selection is kept and the DataGrid does not flicker. but it kind of defeats the purpose.
I found this article but could not make sense of it. I tried a lot of things and nothing worked. In this article the old dojo.connect
syntax is used instead of the new dojo.on
.
I'm sure there's just a detail missing somewhere.
Thank you for your help.