Dojo Datagrid Sort after adding New Item to Store

2019-07-15 14:28发布

问题:

I'm having an issue with a DataGrid not resorting itself after calling newItem() then save() on the store backing the datagrid.

<div dojoType="dojo.data.ItemFileWriteStore" url="/MultiRaterManagerAjax" id="mrWriteStore" jsId="mrWriteStore"</div>     

<table dojoType="dojox.grid.DataGrid" region="left" query="{ hasSub: false }"
        clientSort="true" selectionMode="single"   jsId="ldrSubGrid" sortInfo="1"
        errorMessage="Loading..." store="mrWriteStore">
          <thead>
              <tr>
                  <th width="100%" field="_item" formatter="formatSubs">Subs</th>     
              </tr>

          </thead>
</table>

An event handler calls the following javascript

item = mrWriteStore.newItem({});
//set the necessary attributes on item
mrWriteStore.save({onComplete:afterStoreUpdate, onError: saveFailed});

A new item is added to the store, and the DataGrid is updated showing the new item. But the new item is at the bottom of the list. It doesn't seem to recognize the sorting order of the datagrid.

I'm thinking there is an event I need to connect to (or subscribe to) on the datagrid which tells me it has updated the data. Then I call sort/filter functions when this event is fired. But what to connect/subscribe to?

回答1:

I was struggling with this the other day. I think you need to call the sort() method of the datagrid from inside of your onComplete function, which you have named afterStoreUpdate

dijit.byId('ldrSubGrid').sort();