1. 程式人生 > >bootstrap table保留多選框的分頁

bootstrap table保留多選框的分頁

-a sid ids nsa ide handle ons div body

          initialize : function(options) {
			this.options = options.options;
			this.tableNum=options.tableNum;
			this.selectActive=[];
			this.selections=[];
			this.selectionIds=[];
			this.nowPage;
			this.selectPage=[];
			Table.prototype.initialize.call(this, this.options);
		},
		
		render : function() {
			var _this = this;
			// 創建table節點
			this.$table = $("<table>");
			this.$el.html(this.$table);
              //註意這裏 function responseHandler(res) { $.each(res.rows, function (i, row) { row.checkStatus = $.inArray(row.id, this.selectionIds) != -1; //判斷當前行的數據id是否存在與選中的數組,存在則將多選框狀態變為true }); return res; }; // 初始化表格 this.$table.bootstrapTable({ locale : ‘zh-CN‘, pagination : true, // 默認表格數據排序字段 sortName : "", sortOrder : "", idField:"id",//這裏 pageNumber : _this.tableNum,//這是第幾頁 pageSize : 10, pageList : [], sidePagination : ‘server‘, maintainSelected:true, ajax : $request, url : $request.api + "/patents/query?", queryParams : function(params) { params["columns"] = "applyDate,name,publicDate,inventor,id,updateTime,type,ipcNumber,source,recommended,intentions,price,state,attentions,applyNumber,name,patentee,pageview,transactionType,createType,creator,topTime,createTime"; // 是否有附加參數 if ($.isFunction(_this.getQueryParams)) { params = $.extend(params, _this.getQueryParams()); } _this.nowPage=params.offset/10; return params; }, clickToSelect : true, responseHandler : responseHandler, columns : [{ field: ‘checkStatus‘,checkbox: true, }, {field: ‘id‘,visible:false}, { title : ‘序號‘, formatter : function(value, row, index) { return index + 1; } }, }] }); //通過全部選中數據進行元素獲取 this.showCheck(); //獲取到全部選中的數據 this.clickget() return this; }, clickget:function(){ var mark; var _this=this; var union = function(array,ids){ $.each(ids, function (i, id) { if($.inArray(id,array)==-1){ array[array.length] = id; } }); return array; }; //取消選中事件操作數組 var difference = function(array,ids){ $.each(ids, function (i, id) { var index = $.inArray(id,array); mark=index; if(index!=-1){ array.splice(index, 1); } }); return array; }; var unions = function(arrays,rowa){ $.each(rowa, function (i, row) { if($.inArray(row,arrays)==-1){ arrays[arrays.length] = row; } }); return arrays; }; var differences = function(arrays,rowa){ $.each(rowa, function (i, row) { if(mark!=-1){ arrays.splice(mark, 1); } }); return arrays; }; //綁定選中事件、取消事件、全部選中、全部取消 this.$table.on(‘check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table‘, function (e, rows) { var _ = {"union":union,"difference":difference}; var aa= {"unions":unions,"differences":differences}; var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) { return row.id; }); var rowa= $.map(!$.isArray(rows) ? [rows] : rows, function (row) { return row }); func = $.inArray(e.type, [‘check‘, ‘check-all‘]) > -1 ? ‘union‘ : ‘difference‘; funcs = $.inArray(e.type, [‘check‘, ‘check-all‘]) > -1 ? ‘unions‘ : ‘differences‘; _this.selectionIds = _[func](_this.selectionIds, ids); _this.selection = aa[funcs](_this.selections, rowa); }) }, showCheck:function(){//當分頁點擊的時候顯示之前的選擇 var _this=this; this.$(".bootstrap-table").on(‘post-body.bs.table‘, function () { for(var i=0;i<_this.selectionIds.length;i++){ _this.$("input[value="+_this.selectionIds[i]+"]").attr("checked",true); } }); },

bootstrap table保留多選框的分頁