<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數組中未勾選的複選框。也在複選框選擇當前隱藏列,我想要在模式關閉按鈕。使用上面的代碼,我可以隱藏th而不是td及其數據。根據索引顯示/隱藏列
按照plnk http://plnkr.co/edit/G5bT7G?p=preview
你有什麼saveSelectedColumn方法? – migueref
目前在複選框中選中並取消選中顯示/隱藏表格列。我想在覆蓋的關閉按鈕上執行該操作,例如saveSelectedColumn()。 –