【发布时间】:2016-12-08 03:58:59
【问题描述】:
<div ng-controller="checkBoxController">
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p ng-repeat='(key, val) in employees[0]'>
<label>
<input ng-model='colSettings[$index]' type="checkbox" />{{ key }}</label>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="saveSelectedColumn()">Close</button>
</div>
</div>
</div>
</div>
<div class="panel">
<button type="button" class="btn btn-default" ng-click="tableDataReset();">Reset</button>
<table class="table-condensed" id="employeeTable" border="1">
<thead>
<tr>
<th ng-if='colSettings[$index]' ng-repeat='(key, val) in employees[0]' class="name">{{ key }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees">
<td ng-if='colSettings[$index]'>{{employee.name}}</td>
<td ng-if='colSettings[$index]'>{{employee.age}}</td>
<td ng-if='colSettings[$index]'>{{employee.gender}}</td>
</tr>
</tbody>
</table>
<a href="" title="Column Setting" data-toggle="modal" data-target="#myModal">Settings</a> {{ colSettings }}
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.controller('checkBoxController', function($scope) {
$scope.employees = [{
name: 'John',
age: 25,
gender: 'boy'
}, {
name: 'Jessie',
age: 30,
gender: 'girl'
}];
$scope.colSettings = [true, true, true];
$scope.tableDataReset = function() {
$scope.employees = [{
name: 'John',
age: 25,
gender: 'boy'
}, {
name: 'Jessie',
age: 30,
gender: 'girl'
}];
};
});
有一个带有设置按钮的表格数据列表,单击该按钮会打开一个模式对话框。此模式对话框包含包含等于表中列数的复选框。用户选择任何复选框和关闭按钮,然后根据选中的复选框过滤表格(即仅选中的那些复选框在表格中可见列)。 当前为 colSettings 数组中的选中和未选中复选框存储 true 和 false。同样在复选框选择上,当前隐藏了我想要在模式关闭按钮上的列。使用上面的代码,我可以隐藏 th 但不是 td 及其数据。
【问题讨论】:
-
你在 saveSelectedColumn 方法中有什么?
-
当前选中复选框并取消选中显示/隐藏表格列。我想在覆盖的关闭按钮上执行此操作,即 saveSelectedColumn()。
标签: javascript html angularjs html-table