bootstrap表格結合anglarjs 含全選與全不選(-)
阿新 • • 發佈:2018-07-10
用戶id this 說明 arch mes glob anim != rootscope
} $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]); } }; }
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 含全選與全不選(-)