Angularjs bootstrap table多选(全选),支持单击行选中
来源:互联网 发布:国外mac破解软件网站 编辑:程序博客网 时间:2024/05/16 18:50
最终实现效果:
index.html
<!DOCTYPE html><html> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script> <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.3.1.js"></script> <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="style.css"> <script src="script.js"></script> </head> <body ng-app="routerApp"> <div ng-controller="zdTable"> <table class="table table-bordered" > <thead> <tr> <th> <input type="checkbox" ng-model="selectAll" ng-change="changeAll()" /> 选择</th> <th>序号</th> <th>用户</th> <th>备注</th> <th>操作</th> </tr> </thead> <tbody> <tr ng-repeat="row in datas" ng-init="outerIndex = $index" ng-click="changeCurrents(row, $event)"> <td><input type="checkbox" ng-model="row.checked" ng-click="changeCurrent(row, $event)" /></td> <td ng-bind="outerIndex+1"></td> <td ng-repeat="tddata in row | filterTable"> {{tddata}} </td> <td> <button type="button" class="btn btn-info" ng-click="zdTableEdit(row, $event)">编辑</button> <button type="button" class="btn btn-danger" ng-click="zdTableRemove(row, $event)">删除</button> </td> </tr> </tbody> </table> <div>已选数量:{{count}}</div> <div>已选对象:{{selectData}}</div></div> </body></html>
script.js
// Code goes herevar routerApp = angular.module('routerApp', [ 'ngAnimate', 'ngSanitize', 'ui.bootstrap']);routerApp.controller('zdTable', [ '$scope', function(scope) { console.log('controller'); //初始化数据 scope.datas = [ {name:'admin1', rem:'备注'}, { name:'admin2', rem:'备注'}, { name:'admin3', rem:'备注'} ]; scope.count = 0;//已选择数量 scope.selectData = [];//已选对象 //选择单个(取消选择单个 scope.changeCurrent = function(current, $event) { //计算已选数量 true加, false减 scope.count += current.checked ? 1 : -1; //判断是否全选,选数量等于数据长度为true scope.selectAll = scope.count === scope.datas.length; //统计已选对象 scope.selectData = []; angular.forEach(scope.datas, function(item) { if(item.checked){ scope.selectData[scope.selectData.length] = item; } }); $event.stopPropagation();//阻止冒泡 }; //单击行选中 scope.changeCurrents = function(current, $event) { if(current.checked == undefined){ current.checked = true; }else{ current.checked = !current.checked; } scope.changeCurrent(current, $event); }; //全选(取消全选 scope.changeAll = function() { //console.log(scope.selectAll); angular.forEach(scope.datas, function(item) { item.checked = scope.selectAll; }); scope.count = scope.selectAll ? scope.datas.length : 0; if (scope.selectAll) { scope.selectData = scope.datas; } else { scope.selectData = []; } }; //编辑事件 scope.zdTableEdit = function(item, $event){ console.log(item); $event.stopPropagation();//阻止冒泡 }; //删除事件 scope.zdTableRemove = function(item, $event){ console.log(item); $event.stopPropagation();//阻止冒泡 }; } ]);//去掉不需要显示的字段 routerApp.filter('filterTable', function() { return function(obj) { var newObj = {}; for ( var i in obj) { var property = obj[i]; if(i != 'checked'){ newObj[i] = property; } } //console.log(newObj); return newObj; };});
在线Demo(plunker可能需要翻墙):http://plnkr.co/edit/paA8Fz?p=preview
源码下载:http://download.csdn.net/detail/opingu/9722685
0 0
- Angularjs bootstrap table多选(全选),支持单击行选中
- Angularjs bootstrap table多选(全选),支持单击行选中 ,实现编辑、删除功能
- table支持选中行功能
- bootstrap table获取选中行的值
- bootstrap-table 获取选中的行
- DWZ (JUI)表格Table单击选中功能扩展
- bootstrap-table 实现单击单元格可编辑
- bootstrap table 单击获取当前行号
- bootstrap-table,当前行单击事件
- BootStrap-table 复选框默认选中(checkbox)
- BootStrap-table 复选框默认选中(checkbox)
- table(单击行,把当行的单选按钮(radio)设为选中状态,并应用当前样式)
- Bootstrap Table 双击、单击行获取该行内容及自动获取全表的内容
- AngularJs+Bootstrap Table $compile动态生成html
- bootstrap table 获取选中行数据
- Bootstrap Table 选中某几行,获取其数据
- DEV GridView 单击行选中/取消选中
- GridView鼠标单击选中行
- yum 中文语言包
- 23种设计模式(6):模版方法模式
- KMP 【bzoj3942】 Censoring
- 使用startService方式启动Service
- 关于神经网络中的代价函数——交叉熵的由来
- Angularjs bootstrap table多选(全选),支持单击行选中
- 虚拟化安全怎么做?靠安全设备虚拟化还是换个思路?
- py
- oracle读取评论列表,先按点赞次数取前三名,然后按创建时间倒序排序,需要分页
- 23种设计模式(7):中介者模式
- pwnable part1 溢出研究
- JNI NDK开发笔记
- ionic添加cordova插件-AppVersion
- 事件监听器模式和观察者模式