Dojo DataGrid 1.6在项目插入商店后没有排序

时间:2014-09-08 15:41:53

标签: datagrid dojo

这里有一个类似的问题:Dojo Datagrid Sort after adding New Item to Store 但是我似乎无法应用那里建议的解决方案,也不能将我的问题添加到已接受的答案中,因为我还没有声誉。

我的jsfiddle例子很简单。将新商品添加到商店后,我无法排序。 如果有人可以请一看,我们将不胜感激!

http://jsfiddle.net/mmlitvin/bh48f8d3/3/

以下是完整的代码片段:

debugger;
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojo.parser");

dojo.ready(function() {
    dojo.parser.parse();

    var data = {
        identifier: 'id',
        items: [
            { id:1, col1: false, col2: 'Sally', col3: 45},
            { id:3, col1: false, col2: 'Mary', col3: 98},
            { id:5, col1: true,  col2: 'James', col3: 33},
            { id:6, col1: true,  col2: 'Chris', col3: 72},
            { id:4, col1: false, col2: 'Laura', col3: 12},

        ]
    };

    var store = new dojo.data.ItemFileWriteStore({data: data});

    dijit.byId("grid").setStore(store);
    //dijit.byId("grid")._refresh();  

    //add new item
    dijit.byId("grid").store.newItem(
              { id:2, col1: true,  col2: 'Tom', col3: 23});

   //sort - attempt 1
    dijit.byId("grid").store.save ({
            onComplete:function(){ 
                dijit.byId("grid").sort();
                dijit.byId("grid")._refresh();
                console.debug("Sort invoked");
           }
     });

    //sort - attempt 2
    dijit.byId("grid").store.save();    
    dijit.byId("grid").sort();
    dijit.byId("grid")._refresh();

});

1 个答案:

答案 0 :(得分:0)

尝试指定要排序的列。

//sort - attempt 1
dijit.byId("grid").store.save ({
        onComplete:function(){ 
            // add this to tell the grid to sort on the first column
            dijit.byId("grid").set('sortInfo', 1);

            dijit.byId("grid").sort();
            dijit.byId("grid")._refresh();
            console.debug("Sort invoked");
       }
 });
相关问题