JoelPM

  • 01/19/2009

Dojo: Blank DataGrid Problem

Tonight I ran into a situation where several dojox.grid.DataGrid widgets weren't showing anything, just an empty box - one of them gray, one of them white. The grids are inside other widgets that define views for my objects. When the view widgets are created they set the store for the grids (I'm using JsonRestStore instances) and create the query based on a field in the main object. The grids were showing up fine for objects whose query returned results, so I knew it was related to objects whose query returned an empty array. I believe the problem is in the _onFetchComplete method, but I haven't nailed down why. I'll try to file a bug when I have more information, but for now I'll detail what I did to fix the problem. FIrst, in my main script I declared the following function:
dojo.provide("Fixes");
Fixes.fixDataGrid = function(grid) {
  grid.__onFetchComplete = grid._onFetchComplete;
  grid._onFetchComplete = function(items, req) {
    this.__onFetchComplete(items, req);
    if (!items || items.length == 0) this.update();
  };
}
This function takes a grid and hijacks the _onFetchComplete function, replacing it with my own version that calls the original and then calls update() if no results were returned. In my widgets I 'fix' the grids I've declared in the postCreate() function:
dojo.declare("joelpm.widgets.FooWidget", [dijit._Widget, dijit._Templated], {
  // ...
  postCreate: function() {
    // this.gridAP is the dojoAttachPoint assigned to the grid.
    // The grid must be fixed before setting the store.
    Fixes.fixDataGrid(this.gridAP);

    this.gridAP.setStore(DataStoreManager.forType(Types.Network), this.getQuery());
  }
  // ...
});
Hopefully this will save someone an hour of debugging.


stackoverflow CV
View Joel Meyer's profile on LinkedIn
©2009 Joel Meyer