I am feeling completely lost and could really use some assistance. I have been looking at different examples but nothing seems to be helping me out.
I have created a dynamic table with checkboxes. Whenever a row is selected, its id gets added to an array and displayed at the top of the table.
What I am looking for is the code to implement the select all checkbox functionality. When all rows are selected using the select all checkbox, I want their ids to be displayed.
Below is the code snippet for the table:
<table>
<thead>
<tr>
<th>
<input name="all"
type="checkbox"
ng-click="selectAll()" />
</th>
<th>ID</th>
<th>Date</th>
</tr>
</thead>
<tbody ng-repeat="x in cons">
<tr>
<td>
<input type="checkbox"
name="selectedids[]"
value="{{x.id}}"
ng-checked="idSelection.indexOf(x.id) > -1"
ng-click="toggleSelection(x.id, idSelection)"> </td>
<td>{{x.id}}</td>
<td>{{x.title}}</td>
</tr>
</tbody>
app.js:
$scope.idSelection = [];
$scope.toggleSelection = function toggleSelection(selectionName, listSelection) {
var idx = listSelection.indexOf(selectionName);
// if currently selected
if (idx > -1) {
listSelection.splice(idx, 1);
}
// if newly selected
else {
listSelection.push(selectionName);
}
};
//$scope.selectAll=function(){}
//Need code for this function to work
Check out this demo
: http://plnkr.co/edit/m9eQeXRMwzRdfCUi5YpX?p=preview.
Any guidance on this would be greatly appreciated.