Ext.onReady(function() {
var testData = [
['1','xxxxx'],
['2','aaaa'],
['3','xxyyy'],
['4','bbbb']
];
var selectValue = ['bbbb','aaaa']
var store = new Ext.data.SimpleStore({
fields:['id','name']
});
var sm = new Ext.grid.RowSelectionModel({
listeners:{
'rowselect':function(sm,rowIndex,r){
Ext.log("select",rowIndex,r.get('name'))
}
}
});
var grid = new Ext.grid.GridPanel({
width: 800,
height: 500,
autoScroll: true,
store: store,
sm:sm,
columns: [
sm,
{ header: '序号', dataIndex: 'id', sortable: true },
{ header: '名字', dataIndex: 'name', sortable: true }
]
});
var v = new Ext.Viewport({
items:[grid]
});
store.on('load',function(store,records,options){
var arr=[];
for(var i=0;i
var record = records[i];
var isMatch = selectValue.indexOf(record.get('name'))!=-1;
if(isMatch){
arr.push(record);
}
}
sm.selectRecords(arr);
},this,{delay:1000})
store.loadData(testData);
});
提问者对于答案的评价:
确实是需要延时,谢谢你了~~
其他回答
Ext.grid.CheckboxSelectionModel 是继承Ext.grid.RowSelectionModel的.
看下API:
selectRecords( Array records, [Boolean keepExisting] ) : void
Select records.
Parameters:
records : Array
The records to select
keepExisting : Boolean
(optional) True to keep existing selections
Returns:
void
你可以在store的load事件里面,遍历查找你要的record,
然后执行grid.getSelectionModel().selectRecords(
var sm = grid. getSelectionModel();//获得选择模型
sm.selectAll();
sm.selectFirstRow();
sm.selectLastRow();
selectNext();
selectPrevious();
selectRange( Number startRow, Number endRow, [Boolean keepExisting] ) ;
selectRecords( Array records, [Boolean keepExisting] );
selectRow( Number row, [Boolean keepExisting] );