使用checkboxmodel进行网格加载时如何在默认情况下设置所选行

时间:2013-04-03 09:30:28

标签: extjs extjs4 extjs4.1

2 个答案:

答案 0 :(得分:4)

在Ext JS 4.2.1中运行的经过测试的代码:

grid.on('viewready', function(){
    grid.selModel.doSelect(grid.store.data.items[0]);
});

答案 1 :(得分:2)

总是欢迎更好的解决方案!!!

grid.getStore().load({

scope:this,

callback: function (records, operation, success) {
    if(success){

        /*var store = grid.getStore();
        var records = [];
        store.queryBy(function(record,id){

            if(record.data.chkd){
                    records.push(record);
                }

            console.log(id);

        },this);

        grid.getSelectionModel().select(records,false,false);
        */
          var sm = grid.getSelectionModel();
          Ext.each(records, function(record) {
              if(record.data.chkd){
                var row = record.index;
                sm.select(row, true);
              }
      });



    }else{

        //alert(success);
        //console.log(operation.exception);
    }
}}
);