How to check multiple checkboxes at the same time when one checkbox in datatables is checked
How to check multiple checkboxes at the same time when one checkbox in datatables is checked
miyataka
Posts: 10Questions: 3Answers: 0
Is it possible to implement a title?
Specifically, I want to group the checkboxes so that when one of the groups is checked, the whole group is checked.
This question has an accepted answers - jump to answer
Answers
You will need to provide more details. re you using the select extension with checkboxes?
Are you creating your own checkboxes?
The best thing to do is to provide a test case showing what you have with a description of how you want to group the checkboxes.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you for reply Kevin-san
Yes, I use checkboxes
Unfortunately I can't use the development environment right now.
This is the code I imagine.
i will probably rewrite it again later.
let option = {
data:[
{ NAME: "TOM" , GROUP: "teamA" ,}
{ NAME: "JIM" , GROUP: "teamA" ,}
{ NAME: "MIKE" , GROUP :"teamB" ,}
{ NAME: "BOB" , GROUP: "teamB" ,}
]
}
let table = $('#table').DataTable(option);
//set check all team members
checkTeam = table.prop("checked").('GROUP')
for (let i = 0; i < table.length; i++){
if (table[i]['GROUP'] == checkTeam){
table.row(i).$('.checkbox').prop('checked', true);
}
One option is to use
rows().nodes()
with arow-selector
as a function to get all row nodes with the desired group. Usingto$()
you can apply the.prop('checked', true)
.I built a test case with your example data to show how this can be done:
http://live.datatables.net/baqunepe/1/edit
Kevin
Thank you !
I was able to solve the problem !