Having trouble with rowCallback - saving row selection state

Having trouble with rowCallback - saving row selection state

mihomesmihomes Posts: 165Questions: 23Answers: 0
edited January 2014 in General
Using rowCallback to save the selection state of rows. I have verified with the console log that my 'selected' array is properly storing the rows id, but not getting the expected behavior from the rowcallback function to 'restore' those rows in the array.

[code]
$('#sample_1').dataTable({
"processing": true,
"serverSide": true,
"ajax": "/custom/data-tables/process.php",
// set timestamp as initial sorting
"aaSorting": [[5,'desc']],
// change index column
"columnDefs": [
{
"targets": [ 0 ],
"searchable": false,
"sortable": false,
"render": function ( data, type, row ) {
return '';
}
}
],
"fnDrawCallback": function() {
$('#sample_1 .checkboxes, #sample_1 .group-checkable').uniform();
},
"rowCallback": function( row, data, displayIndex ) {
if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
$(row).addClass('active selected');
}
}
});



var selected = [];

$('#sample_1_wrapper').on('change', 'tbody tr .checkboxes', function () {

var id = $(this).parents('tr').attr("id");
var index = $.inArray(id, selected);

if ( index === -1 ) {
selected.push( id );
}
else {
selected.splice( index, 1 );
}

// add checked status
var checked = $(this).is(":checked");

if (checked) {
$(this).attr("checked", true);
$(this).parents('tr').addClass("active selected");
}
else {
$(this).attr("checked", false);
$(this).parents('tr').removeClass("active selected");
}
});
[/code]

Some additional information. Using console.log in the rowcallback before the if statement to check some values.

[code]
console.log(data.DT_RowId);
console.log(selected);

... returns the following

187413
["187413"]
[/code]

187413 is obviously in the array selected so why it is not returning true and adding the class?

Replies

  • mihomesmihomes Posts: 165Questions: 23Answers: 0
    Had to convert to string - if ( $.inArray((data.DT_RowId).toString(), selected) > -1 ) {
This discussion has been closed.