bootstrap table保留多选框的分页
有时候需要完成这种情况:
1.需要设置的是如果第一页点击复选框然后点击其他页面的话,第一页的选项被保存了
2.将所有选择好的复选款的数据保存在数组中
bootstrap table官方文档http://bootstrap-table.wenzhixin.net.cn/在写之前这个最好看一下
中心思想是:设置两个变量保存选中的数据和对应数据的id,在每次点击分页或者选择复选框的时候都需要根据选择保存到数据中
initialize : function(options) {
this.selections=[];
this.selectionIds=[];//设置一下全局变量,这个表示的是获取每行被选中的id数组
},
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",//这里设置以下表示id的变量
pageNumber : _this.tableNum,//这是第几页
pageSize : 10,
pageList : [],
sidePagination : 'server',
maintainSelected:true,
ajax : $request,
url : $request.api + "/patents/query?",
queryParams : function(params) {
params["columns"] = "xxx";
// 是否有附加参数
if ($.isFunction(_this.getQueryParams)) {
params = $.extend(params, _this.getQueryParams());
}
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保留多选框的分页的更多相关文章
- bootstrap table 保留翻页选中数据
$(function () { $('#exampleTable').on('uncheck.bs.table check.bs.table check-all.bs.table uncheck-al ...
- 前端 | vxe-table 翻页保留复选框状态
0 前言 在前端开发过程中时常会遇到表格相关的显示与处理.组件库通常都会提供表格组件,对于展示.简单操作这些常用功能通常也够用:但如果需要更多的定制或进行比较复杂的操作,组件库自带的组件可能会捉襟见肘 ...
- BootStrap Table显示行号,并且分页后依然递增
bootStrap table 此处使用的是V1.9.0.在网上百度的方法是: { title: '序号', field: '', formatter: function (value, row, i ...
- Bootstrap系列 -- 17. 复选框checkbox和单选择按钮radio
Bootstrap框架中checkbox和radio有点特殊,Bootstrap针对他们做了一些特殊化处理,主要是checkbox和radio与label标签配合使用会出现一些小问题(最头痛的是对齐问 ...
- layui的点击table行选中复选框
$(document).on("click",".layui-table-body table.layui-table tbody tr",function() ...
- elementUITable的多选框:分页选择数据回显,分页保存选中的数据。
<template> <el-table @selection-change="handleSelectionChange" :row-key="get ...
- bootstrap table 复选框选中后,翻页不影响已选中的复选框
使用的 jquery版本为 2.1.1 在项目中发现bootstrap table的复选框选中后,翻页操作会导致上一页选中的丢失,api中的 bootstrapTable('getSelections ...
- BootStrap table使用
bootstrap table git address https://github.com/wenzhixin/bootstrap-table 引入文件 <link rel="sty ...
- 关于复选框input[type=checkbox]
关于复选框input[type=checkbox],其实在前面的文章中说过一次,当时主要关注点在设置复选框的状态,利用prop实现,今天继续关注一下复选框. 自己在项目中,遇到一个全选/全不选的需求, ...
随机推荐
- uboot——详解各目录下的文件作用
uboot下载地址:http://ftp.denx.de/pub/u-boot/ 1.目录分布 2.目录结构变化: u-boot-2010.03及以前版本 ├── api ...
- [Django笔记] Apache + mod-wsgi 环境部署所遇到的各种问题总结
在一台CentOS7机器上配置Django+apache运行环境 Django安装 python2 or python3 ? 一般情况下Linux系统都有自带python2,本机CentOS7上的是p ...
- ASP.NET控件之RegularExpressValidator控件
作用:对Textbox或者其他输入框进行正则验证: 属性:ControlToValidate:要验证的控件: ErrorMessage:错误提示信息: ValidationExpression:正则表 ...
- QuotaExceededError: The quota has been exceeded. localStorage缓存超出限制
今天在项目中遇到了一个问题,localStorage存储超出限制.报错信息如标题.这个是因为最近做了一波优化,把导航栏和一些用户信息本地化存储,都放在localStorage里,也不是每个用户会出现这 ...
- 阿里云服务器 linux 怎么安装php(PHPSTUDY)开发环境
1.首先登录行云管家(https://yun.cloudbility.com/login.html) wget -c http://lamp.phpstudy.NET/phpstudy.bin //下 ...
- (转)TComboBox patch for Delphi 7
unit D7ComboBoxStringsGetPatch; // The patch fixes TCustomComboBoxStrings.Get method . interface {$I ...
- SPA 介绍
SQL 性能分析器(SPA)工具概览 作为 Oracle Real Application Testing 选件/特性,这篇文章将提供一个关于 SQL 性能分析器(SPA)工具的简要概览.这是此系列的 ...
- (转)diff 命令
每天一个linux命令(36):diff 命令 原文:http://www.cnblogs.com/peida/archive/2012/12/12/2814048.html diff 命令是 li ...
- Postman安装步骤
Postman是一种网页调试与发送网页http请求的chrome插件. 我们可以用来很方便的模拟get或者post或者其他方式的请求来调试接口. 1.Postman_v4.1.3下载地址: http: ...
- c/c++技巧总结
1.bzero().memset()初始化结构体. 2.求结构体分量在结构体中地址偏移量 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) ...