JoelPM

  • 01/19/2009

Dojo: DataGrid element stays Editable

And another one while I'm thinking of it: Yesterday night I couldn't figure out why an editable cell in my DataGrid stayed in the editable state even after the update had been applied to the store. It turns out you have to explicitly call updateRow on the row the editable cell exists in to get it to revert to the non-editable state. To do that, you have to set the onApplyCellEdit method on the DataGrid, which you do thusly:
dojo.declare("joelpm.widgets.FooWidget", [dijit._Widget, dijit._Templated], {
  // ...
  postCreate: function() {
    // this.gridAP is the dojoAttachPoint assigned to the grid.
    this.gridAP.onApplyCellEdit = dojo.hitch(this.gridAP, function(inValue, inRowIndex, inAttrName) {
      this.store.save();
      this.updateRow(inRowIndex);
    });
  }
  // ...
});
Note that I'm binding onApplyCellEdit to the grid, not to my local class, which gives me easy access to the grid's variables (the store is what I'm interested in) and functions. I'm also saving the data store in the process, but whether or not you do that depends on how you've got your widgets set up - if you've got a "Save" button somewhere you don't want to do what I'm doing.


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