Issue with dataTable statesave
Issue with dataTable statesave
Hi
I am using datatable 1.9 for my application. My application updates table on every 30 seconds. I am calling table.ajax.reload() function for update. I have table initialization parameters change dynamically based on actions in my application. But problem is on every update datatable is not changing initialization parameters dynamically instead it is drawing based on initial value.
My datatable code is:
function drawTable(id,url){
if (table) {
table = $('#example').DataTable();
$(document).find('#example_filter label').each(function() {
$(this).find('input').each(function() {
$(this).attr('id', 'tableSearchText');
tableSearchText = $(this).val();
});
});
table.destroy();
} else {
colIndex = 0;
sortingOrder = 'asc';
currentPage = 1;
noOfPages = 10;
tableRecordsLength = 10;
}
var alarmCount = 0;
var temp = tableRecordsLength * 10;
table = $('#example').dataTable({
"pagingType" : 'full_numbers',
"order" : [ colIndex, sortingOrder ],
"bPaginate" : getPaging(),
"displayStart" : getDisplayStart(),
"scrollY" : getHeight(),
"lengthChange" : getPaging(),
"lengthMenu" : [ [ 10, 25, 50, 100, -1 ],
[ 10, 25, 50, 100, "All" ] ],
"pageLength" : temp / 10,
"search" : {
"caseInsensitive" : true,
"regex" : true,
"smart" : false
},
"ajax" : {
"url" : url,
"dataType" : "json",
"data" : function(d) {
d.alertId = id;
d.selectedIdArray = $('#sel_Array').val();
d.alertNumbers = $('#sel_Alert_Array').val();
},
"type" : "POST",
"error" : handleTableError
},
"aoColumns" : [ {
"mData" : "AlertId",
"sTitle" : "ALERT ID",
"bVisible" : toggleAlertId,
"bSearchable" : true,
"sWidth" : "10%",
"sType" : "natural"
}, {
"mData" : "Desc",
"sTitle" : "ALERT MESSAGE",
"bVisible" : toggleAlertMsg,
"bSearchable" : true,
"sWidth" : "25%",
"sType" : "natural"
} ],
"deferRender" : true,
"fnRowCallback" : function(nRow, mData,iDisplayIndex, iDisplayIndexFull) {
//Some Logic.
}
}
For update I'm using:
var table=$('#example').DataTable();
table.ajax.reload(null,false);
table.Draw();
I have tried with saveState and saveStateCallback function. No use...
Toggling, paging nothing worked for me.. I tried to print the dynamic values returned by the functions.. table.ajax.reload is not actually calling the method. So, It keeps in memory, values the very first time I loaded. So, for Toggling I've managed somehow using logic and at the end by calling
var oTable = $('#example').dataTable();
var bVis = oTable.fnSettings().aoColumns[colIndex].bVisible;
oTable.fnSetColumnVis(colIndex, bVis ? false : true);
$('.refreshImg').trigger("click");
But problem is on every refresh Table getting reset to first page..
So, I externally tried with
$(document).find('#example_paginate span a').each(
function() {
if ($(this).text() == currentPage)
$(this).trigger("click");
}); but problem is, the dom contains one table page numbers 1 to 6 and dots upto lastnumber - 1.
So on redraw the pages are reset by automatic and If I want to click any numbers between the dots like 20,21.. On update it is not reflecting...
Help me out...