Issues with setting selected row
Issues with setting selected row
I'm a bit stumped as to why I can't seem to set the selected row and why after a table.ajax.reload( null, false ) the selected row indicator on the bottom of the page gets reset it seems. What I mean by this is the info at the bottom of the table will say "Showing 1 to 15 of 256 entries 1 row selected" after the ajax reload it will say just "Showing 1 to 15 of 256 entries". the selected row does not change color when this occurs. As well, it seems data tables is still aware of the selected row because I can still get the proper selected id despite graphically it seems to indicate that nothing is selected.
My main issue however is that I'm unable to select a new row. I have tried several approaches from the documents and forums but with no success so far. When I try it seems nothing is happening, I do not see the class Selected get added to the row id I passed nor do I receive any error messages.
Thanks for any help. :)
This is an example of the server returned data:
{"draw":1,"recordsTotal":256,"recordsFiltered":256,"data":[{"DT_RowId":"id_1","0":"10.0.0.0","1":"255.255.255.255","2":"HOST","3":"AVAILABLE","4":null,"5":null,"6":null,"7":null,"8":null,"9":null,"10":"test","11":"2016-04-17 18:15:37","12":null,"13":null},{"DT_RowId":"id_2","0":"10.0.0.1","1":"255.255.255.255","2":"HOST","3":"AVAILABLE","4":null,"5":null,"6":null,"7":null,"8":null,"9":null,"10":"test","11":"2016-04-17 18:15:37","12":null,"13":null}, <SNIP>
$(document).ready(function() {
var table = $('#IPAddressTable').DataTable({
scrollY: '50vh',
"bLengthChange": false,
scrollX: true,
scrollCollapse: true,
deferRender: true,
"pageLength": 256,
scroller: {
loadingIndicator: true
},
"order": [[ 0, "asc" ]],
"columnDefs": [
{
"type": 'ip-address',
"targets": [ 1 ],
}
],
dom: '<lf<t>B<"clear">i>',
buttons: [
'colvis',
'copy',
'print',
'excel'
],
processing: true,
serverSide: true,
rowId: 'DT_RowId',
select: {
style: 'single'
},
"ajax":{
url :"/Processing-IPAM-IPv4Table.php?tableName=" + IPtable,
//type: "post", // method , by default get
error: function(){ // error handling
$(".IPAddressTable-error").html("");
$("#IPAddressTable").append('<tbody class="IPAddressTable-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#IPAddressTable_processing").css("display","none");
}
}
} );
// Refresh table data every min
setInterval( function () {
table.ajax.reload( null, false );
}, 60000 );
$('#updateModal').on('hidden.bs.modal', function () {
Cookies.set('selectedIPAMv4ModalClose', true, { path: '' });
var cookieRowID = Cookies.get('selectedIPAMv4Row', { path: '' });// Get Selected Row ID eg: id_1
var id = cookieRowID.replace("id_", "");
var table = $('#IPAddressTable').DataTable();
//table.row( {selected: true, page: 'current' } ).id(cookieRowID); //Tried this but no luck.
table.row(table.row( cookieRowID )).select();
var formData = {
'task' : "RELEASE-ROW-RELOAD",
'userName' : userName,
'tableName' : IPtable,
'rowID' : id,
};
$.ajax({
type : 'GET',
url : 'Function-IPAMv4.php',
data : formData, // our data object
dataType : 'json', // what type of data do we expect back from the server
encode : true,
})
// using the done promise callback
.done(function(data) {
var passedVariables = '?tableName=' + IPtable;
Cookies.set('IPAMv4Reloading', true, { path: '' });
if(data.task_result == "SUCSESS"){
table.ajax.reload( null, false );
} else {
table.ajax.reload( null, false );
console.log('Error: An error occured releasing the row you where updating!');
}
// here we will handle errors and validation messages
});
} );