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

miyatakamiyataka 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

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    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

  • miyatakamiyataka Posts: 10Questions: 3Answers: 0

    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.

    CHECKBOX NAME GROUP

    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);
    }

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    One option is to use rows().nodes() with a row-selector as a function to get all row nodes with the desired group. Using to$() 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

  • miyatakamiyataka Posts: 10Questions: 3Answers: 0

    Thank you !
    I was able to solve the problem !

Sign In or Register to comment.