0
<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><label><input type="checkbox" id="name" />Name</label></p>
<p><label><input type="checkbox" id="age" />Age</label></p>
<p><label><input type="checkbox" id="gender" />Gender</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">
<thead>
<tr>
<th class="name">Name</th>
<th class="age">Age</th>
<th class="gender">Gender</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees">
<td>{{employee.name}}</td>
<td>{{employee.age}}</td>
<td>{{employee.gender}}</td>
</tr>
</tbody>
</table>
<a href="" title="Column Setting" data-toggle="modal" data-target="#myModal">Settings</a>
</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.saveSelectedColumn = function(){
$scope.selectCheckBox = [];
var $tbl = $("#employeeTable");
var $tblhead = $("#employeeTable th");
$("#myModal").find("input[type='checkbox']").each(function(index) {
//$scope.selectCheckBox = [];
var checked = $(this).is(":checked");
if(checked)
$scope.selectCheckBox.push(1);
else
$scope.selectCheckBox.push(0);
var checked = $(this).is(":checked");
var colToHide = $tblhead.filter("." + $(this).attr("id"));
var index = $(colToHide).index();
if(checked)
$tbl.find('tr :nth-child(' + (index + 1) + ')').show();
else
$tbl.find('tr :nth-child(' + (index + 1) + ')').hide();
});
localStorage.setItem("localData", JSON.stringify($scope.selectCheckBox));
}
$scope.tableDataReset = function(){
$scope.employees=[{name:'John', age:25, gender:'boy'},
{name:'Jessie', age:30, gender:'girl'}];
var getLocalStorageDate = localStorage.getItem("localData");
var testData = JSON.parse(getLocalStorageDate);
if(testData != undefined && testData != null){
//alert(testData.length);
}
}
});
具有設置按鈕的列表數據,其中模式對話框打開。這種模式對話框包含的複選框等於表中的數字列。用戶選擇任何複選框&關閉按鈕,然後根據檢查的複選框(即只檢查列中在列表中可見的複選框)過濾表格。當用戶按下模式關閉按鈕我正在存儲狀態是0 & 1在陣列內localstorage(即1爲檢查& 0爲未選中)。有一個重置按鈕onclick,我填寫表後,但我想只顯示那些列取決於存儲在localstorage中的值爲0 & 1.我正在面對的問題,重置點擊復位按鈕時的數據。請找到所附的plnkr。Jquery/Angular根據存儲在本地存儲中的值顯示/隱藏列
它的工作非常感謝。同樣根據你給出的建議,你可以請我分享如何以這種方式完成,因爲我是一名初學者,所以非常感謝你的幫助。 –
@jinishshah你應該使用角度ng-show/ng-hide根據複選框的條件你想顯示/隱藏TH和TD的列。您可以實現工作結果[使用此解決方案] [http://stackoverflow.com/questions/17327381/toggling-dynamic-table-columns-with-checkboxes-in-angular] – Nusix