How to access the checkbox inside a cell via row selection
How to access the checkbox inside a cell via row selection
Hi I am new to DataTable and I have an issue, this maybe common but I'm stuck with it for days.
I have place a checkbox inside a cell of my DataTable
{"data": null,
render: function (data) {
return "<input type='checkbox' class='chkClass' />";
},}
and I want it to be checked/unchecked everytime the row is selected, I have tried what I saw online but to no avail here are my codes
$('#myTable tbody').on('click', 'tr', function () {
$(this).toggleClass('selected');
if ($(this).hasClass("selected")) {
$(this).closest("input[type='checkbox'].chkClass").eq(0).prop('checked', true);
} else {
$(this).closest("input[type='checkbox']").eq(0).prop('checked', false);
}
});
hoping for your kind support, TIA.
This question has an accepted answers - jump to answer
Answers
The easiest way is with the Select Extension using this example:
https://datatables.net/extensions/select/examples/initialisation/checkbox.html
If this doesn't help then please provide a test case with your code so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you @kthorngren for your quick response but what I want is a multiple row selection. when I select a row, the checkbox will be check and when I select another row, the ones that selected will remain checked.
If you are using the Select Extension then you can control this with the
select.style
option. You can set it tomulti
or one of the other options that meets you needs. Here is an example without the checkboxes:https://datatables.net/extensions/select/examples/initialisation/multi.html
Kevin
thank you, exactly what I wanted