Hi guys. I got a requirement where I need to check the checkboxes based on given input IDs
Hi guys. I got a requirement where I need to check the checkboxes based on given input IDs

Link to test case:
vm.dataTableInstance = $('.datatable-basic').DataTable({
data : vm.ListValues,
columns : [
{data : 'selectedValue', orderable: false,
targets: 0, render : function(data, type, row){
return '<input className=select-checkbox type="checkbox"' + (data ? ' checked="checked"' : '') + '><span> </span>';**:
Hi team , i got a requirement where I need to check the checkboxes based on given input IDs. Using a datatable button i have given the input ids for which i need the checkboxes to be checked. I am able to check the checkboxes of given input values. Here only td value is marked as checked but tr values does not have any selected class in it. Due to that when I am trying to fetch the selected rows , i didn't get any rows from the table even if the check boxes are checked. So my question is how will I add selected class in tr when I am constructing datatable:
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
Answers
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Are you using the Select Extension? If yes then you might be interested in the checkox example. Use the
row().select()
API to select the row whether you use the checkbox example or your checkbox code.Kevin
vm.dataTableInstance = $('.datatable-basic').DataTable({
data : vm.List,
columns : [
{ data : 'selectedValue', orderable: false,
className: 'select-checkbox',
targets: 0, render : function(data, type, row){
if(data === true){
$(this).closest('tr').addClass('selected');
}
return '<span> </span>';
}},
{ data: 'name', title : 'Name', width : '5%' }
based on selectedValue as true I need to make the row as selected by default.
``vm.dataTableInstance = $('.datatable-basic').DataTable({
data : vm.List,
columns : [
{ data : 'selectedValue', orderable: false,
className: 'select-checkbox',
targets: 0, render : function(data, type, row){
if(data === true){
$(this).closest('tr').addClass('selected');
}
return '<span> </span>';
}},
{ data: 'name', title : 'Name', width : '5%' }`
The
columns.render
function is for manipulating the row data not the row element. Use eithercreatedRow
orrowCallback
to do this.createdRow
runs once androwCallback
runs each time the table is drawn. UserowCallback
if the data changes and you need to continue selecting rows based on the changes. The docs for each have simple eamples.Kevin