bootstrap表格结合anglarjs 含全选与全不选(-)

Posted loveAline

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bootstrap表格结合anglarjs 含全选与全不选(-)相关的知识,希望对你有一定的参考价值。

http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/

html--------------

<table id="mytab" class="table table-hover"></table>
js-----------------------
$scope.pageSize=20; //条数
$scope.orgnizationname = ""; //名字
$scope.mustcheck = 0; //是否必查
$scope.deleteArr = [] //存放要删除的任务ID
$scope.request = function(sendData){
HikGlobalHTTPService.requestByPost("/api/organization/search", sendData, function (data, status){
if(status){
// layer.close(loading);
$scope.totalNum = data.totalNum; //数据总条数
if(data.result == null || data.result.length == 0){
$scope.tableData = [];
$rootScope.pageNum = 1;
$rootScope.totaPage = 1;
}else{
$scope.tableData = data.result;
$rootScope.totaPage = Math.ceil($scope.totalNum/$scope.pageSize); //总页码数
}
$(‘#mytab‘).bootstrapTable({
url: ‘‘,
columns: [
{checkbox:true,width:‘3%‘},
{width:‘4%‘,title:‘序号‘,align:‘center‘,formatter:function(value, row, index){
return index+1;
}},
{width:‘12%‘,title:‘责任组织名称‘,align:‘center‘,formatter:function(val,row,index){
 
return ‘<span class="taskNameOrg f_blue" title="‘+row.orgnizationname+‘">‘+row.orgnizationname+‘</span>‘;
},events:{
"click .taskNameOrg":function(e,value,row,index){
$(‘.mask_texts‘).hide();
$(‘.input_contents‘).hide();
$(‘.input_contentshows‘).html(row.orgnizationname).css({border:"none"});
$(‘.mask_text_shows‘).html(row.description).css({border:"none"});
var layer = layui.layer;
layer.open({
type: 1,
area: [‘462px‘, ‘345px‘],
title: [‘详情‘, ‘font-size:15px;background:#e60012;color:#fff;‘],
content: $(‘.mask‘),
btn: [‘确定‘, ‘取消‘],
yes: function (index, layero) {
layer.close(index); //如果设定了yes回调,需进行手工关闭
maskHide();
},
btn2: function () {
maskHide();
}
});
closeBtn();
},//显示
}},
{width:‘8%‘,title:‘说明‘,align:‘center‘,formatter:function(value,row,index){
return ‘<span title="‘+row.description+‘">‘+row.description+‘</span>‘;
}},
 
{width:‘6%‘,title:‘操作‘,align:‘center‘,formatter:function(value,row,index){
return[
‘<span class="editData"></span>‘,
‘<span class="deleteData"></span>‘
].join("");
},events:{
"click .editData":$scope.editDataTask,//编辑
"click .deleteData":function(e,value,row,index){//删除
var abarbeitungPopups = layer.open({
content: "确认是否删除?",
title: "",
closeBtn: false,
btn: ["确定","关闭"],
yes: function(){
layer.close(abarbeitungPopups);
var dateId=[];
dateId.push(row.id);
HikGlobalHTTPService.requestByPost("/delete",{id:dateId}, function (data, status){
if(status){
$rootScope.queryData();//删除刷新
}
})
}
})
 
}
}}
],
data: $scope.tableData,
height: ‘100%‘,
onCheckAll:function(row){ //全选
$scope.deleteArr = [];
for(var i = 0; i < row.length; i++){
$scope.deleteArr.push(row[i].id);
}
},
onUncheckAll:function(row){ //取消全选
$scope.deleteArr = [];
},
onCheck:function(row){ //单行选中
$scope.deleteArr.push(row.id);
},
onUncheck:function(row){ //取消单行
for(var i = 0; i < $scope.deleteArr.length; i++){
if($scope.deleteArr[i] == row.id){
$scope.deleteArr.splice(i,1);
break;
}
}
}
})
$rootScope.pageJudge();
}else{
// layer.close(loading);
layer.open({
content: data.message
})
}
})
}
$scope.request({id:1,pageSize:$scope.pageSize,pageNum:$rootScope.pageNum});//用户id
$scope.editDataTask = function(e,value,row,index){ // 编辑
$(‘#inputData‘).val(row.orgnizationname);
$(‘#input_text‘).val(row.description);
var layer = layui.layer;
layer.open({
type: 1,
area: [‘462px‘, ‘345px‘],
title: [‘说明‘, ‘font-size:15px;background:#e60012;color:#fff;‘],
content: $(‘.mask_edit‘),
btn: [‘确定‘, ‘取消‘],
yes: function (index, layero) {
layer.close(index); //
maskHide();
var taskInputName = $(‘#inputData‘).val();//
var taskDescription = $(‘#input_text‘).val();//
$scope.editDate= function () { // 编辑
var requestBody = {};
requestBody.orgnizationname = taskInputName;
requestBody.description = taskDescription;
requestBody.id = row.id;
var postData = requestBody;
HikGlobalHTTPService.requestByPost("/update", postData, function (data, status) {
if (status) {
if(data.status=="SUCCESS"){
$rootScope.queryData();//删除刷新
}else{
var abarbeitungPopups = layer.open({
content: data.message,
title: "",
closeBtn: false,
btn: ["确定"],
yes: function () {
layer.close(abarbeitungPopups);
 
}
})
}
 
}
});
};
 
if(taskInputName!=‘‘){
$scope.editDate();
}else{
var abarbeitungPopups = layer.open({
content: "*为必填",
title: "",
closeBtn: false,
btn: ["确定"],
yes: function () {
layer.close(abarbeitungPopups);
 
}
})
}
 
 
},
btn2: function () {
maskHide();
}
});
closeBtn();

}
$rootScope.queryData = function(){// 搜索
$("#mytab").bootstrapTable(‘destroy‘);//清除
if($scope.orgnizationname == ""){
var tasksname = null;
}else{
var tasksname = $scope.orgnizationname;
}
var sendData = {
id: $rootScope.orgid, //用户ID $rootScope.orgid
pageSize: $scope.pageSize, //每页显示条数
pageNum: $rootScope.pageNum, //当前页码
orgnizationname: tasksname, 
}
$scope.request(sendData);
}
// 重置搜索条件
$scope.reset = function(){
$scope.orgnizationname = "";

}
$scope.add_task = function(){//添加
$(‘#inputData‘).val("");
$(‘#input_text‘).val("");
var layer = layui.layer;
layer.open({
type: 1,
area: [‘462px‘, ‘345px‘],
title: [‘添加责任组织‘, ‘font-size:15px;background:#e60012;color:#fff;‘],
content: $(‘.mask_edit‘),
btn: [‘确定‘, ‘取消‘],
yes: function (index, layero) {
var taskInputName = $(‘#inputData‘).val();
var taskDescription = $(‘#input_text‘).val();
if(taskInputName!=‘‘){
var requestBody = {};
requestBody.orgnizationname = taskInputName;
requestBody.description = taskDescription;
var postData = requestBody;
HikGlobalHTTPService.requestByPost("/api/organization/add", postData, function (data, status) {
if (status) {
if(data.status=="SUCCESS"){
$rootScope.queryData();//刷新
}else{
var abarbeitungPopups = layer.open({
content: data.message,
title: "",
closeBtn: false,
btn: ["确定"],
yes: function () {
layer.close(abarbeitungPopups);
 
}
})
}
 
}
});
layer.close(index); //如果设定了yes回调,需进行手工关闭
maskHide();
}else{
$(‘.prompt‘).stop().animate({
top: ‘2px‘
});
}
},
btn2: function () {
maskHide();
}
});
closeBtn();
}
$scope.deleteTask = function(){//删除
var idStr = "";
for(var i = 0; i < $scope.deleteArr.length; i++){
if(i == $scope.deleteArr.length - 1){
idStr += $scope.deleteArr[i];
}else{
idStr += $scope.deleteArr[i] + ",";
}
}
var dataStrArr=idStr.split(",");//分割成字符串数组
var dataIntArr=[];//保存转换后的整型字符串 int类型

dataStrArr.forEach(function(data,index,arr){
dataIntArr.push(+data);
});
var abarbeitungPopups = layer.open({
content: "确认是否删除?",
title: "",
closeBtn: false,
btn: ["确定","关闭"],
yes: function(){
layer.close(abarbeitungPopups);
HikGlobalHTTPService.requestByPost("/del",{id:dataIntArr}, function (data, status){
if(status){
$rootScope.queryData();//删除刷新
}
})
}
})
}
 
 
----------------------forEach兼容ie8
if (typeof Array.prototype.forEach != ‘function‘) {//兼容ie8
Array.prototype.forEach = function(callback){
for (var i = 0; i < this.length; i++){
callback.apply(this, [this[i], i, this]);
}
};
}



以上是关于bootstrap表格结合anglarjs 含全选与全不选(-)的主要内容,如果未能解决你的问题,请参考以下文章

Bootstrap之表格checkbox复选框全选 [转]

Vue指令实战:结合bootstrap做一个用户信息输入表格

Vue指令实战:结合bootstrap做一个用户信息输入表格

基于bootstrap + php +ajax datatable 插件的使用

使用bootstrap-table的客户端分页(结合ajax)和服务端分页渲染表格

Bootstrap 多选全选默认选中