首页 > 代码库 > bootstrap table保留多选框的分页

bootstrap table保留多选框的分页

          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="http://www.mamicode.com/+_this.selectionIds[i]+"]").attr("checked",true); } }); },

 

bootstrap table保留多选框的分页