views:

69

answers:

1

Hi all,

I've got some code that requests some data from a servlet, and renders it in a dojox.grid.DataGrid. This seems to be rather slow though! I'm stuck on how to make it faster. Can anyone help out?

I'm testing with

Dojo 1.34 FF & Chrome.

My code remove all items in the dojo.data.ItemFileWriteStore, then adds new ones that come back from a JSON request.

 //Define globla var for the WriteStore...
 var deltaInfo;
 var rawdataDeltaInfo = <s:property value='%{deltaTableData}'/>;
 deltaInfo = new dojo.data.ItemFileWriteStore({
     data: {
         items: rawdataDeltaInfo
     }
 });

This section of code to remove all the existng data take 2seconds, even though it only has 30 rows. Any ideas how to make this quicker?

 function requestJSONFeed(){
     // remove all existing data...
        var allData = deltaInfo._arrayOfAllItems;
     for (i=0;i<allData.length;i++) {
       if (allData[i] != null) {
        deltaInfo.deleteItem(allData[i]);
       }
     }
     deltaInfo.save();

     // make JSON XHR request...
   var xhrArgs = {
  url: "../secure/jsonServlet",
     handleAs: "json",
     preventCache: true,
     load: function(data) {
         // Add new items to the store...
       for (i=0;i<data.length;i++) {
        deltaInfo.newItem(data[i]);
      }
     },
     error: function(error) {
     }
 }

 //Call the asynchronous xhrGet
 var deferred = dojo.xhrGet(xhrArgs);

}

The section of code above to add 30 new items takes 4 seconds. Any ideas on how to make this faster?

Thanks!

Jeff Porter

FINAL CODE...

var xhrArgs = {
url: "../secure/jsonServlet",
 handleAs: "json",
 preventCache: true,
 load: function(datax) {
     deltaInfo = new dojo.data.ItemFileWriteStore({data: {items:datax}});
     var grid = dijit.byId("gridDeltas");
     grid.setStore(deltaInfo);
 },
 error: function(error) {
 }
+1  A: 

Try skipping the code that walks through the existing store, deletes every item and then does deltaInfo.save(). Instead, create a brand new store based on your xhr call, and then use dojox.grid.DataGrid.setStore().

kschneid
We use setStore for this reason. However, we have had some errors occur when setStore is called in rapid succession. For instance, in an explorer-like tree/grid combination, we have to throttle the changes when the tree is clicked on.
Erin Stanfill
Thanks for the info kschneid!I've added my final code to my question above.
jeff porter