timeArray = new Array(); //临时数组变量
var timeStatusBar = new Ext.ux.StatusBar({
id: 'statusbar',
defaultText: '选择时间列表',
});
var timeSelectModel = new Ext.grid.CheckboxSelectionModel({
checkOnly:true,
singleSelect:false,
listeners:{
rowselect:function(sm, rowIndex, record){ //选择事件,将time添加到timeArray中
var time = record.data.time;
if (!ArrayContains(timeArray, time)){
//timeArray中没有存储time,则添加到timeArray中
var link = '<a href="javascript:removeTime_result('+time+')" target="_blank" rel="external nofollow" ><img src="/NetMonitor/Images/common/delete.gif"/></a>';
ArrayAppendDesc(timeArray, time, [time, link]);
timeStore_result.loadData(timeArray);
}
},
rowdeselect:function(sm, rowIndex, record){ //取消选择事件,从timeArray中移除出去
//临时变量中存储了这个time,则从timeArray中移除出去
var time = record.data.time;
ArrayRemove(timeArray, time);
timeStore_result.loadData(timeArray);
}
}
});
var timeColumnModel = new Ext.grid.ColumnModel([
{ header:'时间选择列表',dataIndex:'time',width:200,align:'center'},
timeSelectModel
]);
var timeRecordType = Ext.data.Record.create([{name:'time'}]);
var timeStore = new Ext.data.Store({
id:'timeStore',
proxy:new Ext.data.DWRProxy(ExcelDaoService.getGridTime_ExcelDao,false),
reader:new Ext.data.ListRangeReader({
root:'data',
totalProperty:'totalSize'
},timeRecordType)
,
listeners:{
beforeload:function(){
timeStore.baseParams = {table:table};
},
load:function(){ //加载的时候,根据临时变量timeArray勾选
var records = new Array();
timeStore.each(function(record){
for(var i=0; i<timeArray.length; i++){
if(timeArray[i][0] == record.data.time){
records.push(record);
}
}
});
timeSelectModel.selectRecords(records, true);
}
},
remoteSort:true
});
var pageTBar=new Ext.PagingToolbar({
id:'pagingTbr',
pageSize: 20,
store:timeStore,
afterPageText:'共{0}页',
beforePageText:"当前页",
lastText:"尾页",
nextText:"下一页",
prevText:"上一页",
firstText:"首页"
});
var timeGrid = new Ext.grid.GridPanel({
id:'timeGrid',
tbar:timeStatusBar,
bbar:pageTBar,
cm:timeColumnModel,
sm:timeSelectModel,
store:timeStore,
autoScroll:true,
stripeRows:true,
height:540
});
Ext grid checkbox在翻页的过程中,会碰到之前勾选的数据,无法记录的情况,这时就应该使用一个临时array变量存储勾选的值,然后在grid每次load的时候,把每行数据与该array变量进行遍历判断,这样就能实现翻页保持勾选数据的效果。