Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 51fcba1

Browse files
committed
Improve doc example
Added toggle one to set the check state of the title header checkbox. For example, if all rows are checked, automatically mark the header checkbox checked and vice versa. Signed-off-by: Jack Yen <[email protected]>
1 parent 21657a5 commit 51fcba1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

demo/advanced/rowSelect.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function RowSelect($compile, $scope, $resource, DTOptionsBuilder, DTColumnBuilde
77
vm.selected = {};
88
vm.selectAll = false;
99
vm.toggleAll = toggleAll;
10+
vm.toggleOne = toggleOne;
1011

1112
var titleHtml = '<input type="checkbox" ng-model="showCase.selectAll"' +
1213
'ng-click="showCase.toggleAll(showCase.selectAll, showCase.selected)">';
@@ -30,7 +31,8 @@ function RowSelect($compile, $scope, $resource, DTOptionsBuilder, DTColumnBuilde
3031
DTColumnBuilder.newColumn(null).withTitle(titleHtml).notSortable()
3132
.renderWith(function(data, type, full, meta) {
3233
vm.selected[full.id] = false;
33-
return '<input type="checkbox" ng-model="showCase.selected[' + data.id + ']"/>';
34+
return '<input type="checkbox" ng-model="showCase.selected[' + data.id + ']"' +
35+
'ng-click="showCase.toggleOne(showCase.selected)"/>';
3436
}),
3537
DTColumnBuilder.newColumn('id').withTitle('ID'),
3638
DTColumnBuilder.newColumn('firstName').withTitle('First name'),
@@ -50,4 +52,16 @@ function RowSelect($compile, $scope, $resource, DTOptionsBuilder, DTColumnBuilde
5052
}
5153
}
5254
}
55+
function toggleOne (selectedItems) {
56+
var me = this;
57+
for (var id in selectedItems) {
58+
if (selectedItems.hasOwnProperty(id)) {
59+
if(!selectedItems[id]) {
60+
me.selectAll = false;
61+
return;
62+
}
63+
}
64+
}
65+
me.selectAll = true;
66+
};
5367
}

0 commit comments

Comments
 (0)