Get Checkbox in Current Row
Get Checkbox in Current Row
Davey Jones
Posts: 7Questions: 3Answers: 0
I am iterating through my datatable using
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
});
and I want to see if the checkbox in the row is checked. The checkbox was created using render, but the rest of the table was populated through AJAX. I can use var data = this.data();
to get the rest of the data elements, but I'm having trouble getting that checkbox.
Here is where I am setting up the datatable:
$('#myTable').DataTable({
ajax: {
type: 'GET',
url: '/myController/myMethod',
data: {
argument1: obj.Var1,
argument2: obj.Var2,
argument3: obj.Var3
},
dataSrc: '',
error: function (xhr, status, error) {
alert("error occurred");
}
},
columns: [
{
targets: 0,
data: 'Checked',
searchable: false,
orderable: false,
width: '1%',
className: 'dt-center',
render: function (data, type, full, meta) {
if (data){
return '<input type="checkbox" checked>';
}
else {
return '<input type="checkbox">';
}
},
createdCell: function (td, cellData, rowData, row, col) {
$(td).prop("scope", "row");
}
},
{
targets: 1,
data: 'someData1'
},
{
targets: 2,
data: 'someData2'
},
],
order: []
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Here is one option you can try:
EDIT: Sorry noticed you had a specific function noted. This might work for you:
Kevin
That did the trick. Thanks Kevin. I wasn't aware of the
.node()
method, and I was originally thinking I had to do something likerow().cell(0)
or something to that effect. I ended up going with your second method: