天天看點

Ext grid checkbox 分頁 翻頁 勾選 問題

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變量進行周遊判斷,這樣就能實作翻頁保持勾選資料的效果。