【问题标题】:Dojo DataGrid 1.6 not sorting after item inserted into the storeDojo DataGrid 1.6 在将项目插入商店后不排序
【发布时间】:2014-11-01 21:28:20
【问题描述】:

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

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

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

这是完整的sn-p代码:

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();

});

【问题讨论】:

    标签: datagrid dojo


    【解决方案1】:

    尝试指定排序依据。

    //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");
           }
     });
    

    【讨论】:

      猜你喜欢
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 2014-09-02
      相关资源
      最近更新 更多