1

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.

Micha Roon
  • 3,957
  • 2
  • 30
  • 48

1 Answers1

0

In the latest version of dojo, the public refresh() method of the DataGrid has been removed. You can get access to the private member by usingformGrid._refresh().

Be aware that they must have removed the public function for some reason and this goes against the philosophy of OOPS.

As general advice, under circumstances where no other solution can be found, try typing formGrid. into the single line mode of firebug's console. When you type the .you get a list of all members and properties of the object in question including all public ones (usually no _ in the beginning) and all private ones (usually an _ in the beginning).

If it doesn't work in firebug, try the excellent console in chrome.

Gaurav Ramanan
  • 3,655
  • 2
  • 21
  • 29