Datatables is making two requests to my server [with debug table]
Datatables is making two requests to my server [with debug table]
codemonk
Posts: 24Questions: 0Answers: 0
table debug: http://debug.datatables.net/ewuxer
Hello, I noticed that my data table is making two request to my server. I decided to debug it with the tool provided and i noticed I am drawing the table twice. Here is my initialization. Has anyone experience similar issue. I am not using the provided php server to process my data if that helps.
UPDATE:I created an alert inside of my fnDrawCallback and i do get 2 alerts. :(
[code]
function buildTable()
{
oTable = $('#example').dataTable({
"bJQueryUI": true,
//"bStateSave": true,
"iDisplayLength": 50,
//"bProcessing": true,
"bServerSide": true,
"bRetrieve": true,
"sAjaxSource": "http://dev1.ocp:8888/server",
"sPaginationType": "full_numbers",
"sDom": 'R<"H"lfr>t<"F"ip<',
"bScrollCollapse": false,
"bAutoWidth": false,
"fnDrawCallback": function(oSettings) {
//Checks for Rows, if empty, disables add row.
//Empty row set oTable.fnSettings().fnRecordsTotal()
if(oTable.fnSettings().aoColumns.length == 1)
{
$("#btn-row-add").button({disabled: true});
}
else
{
$("#btn-row-add").button({disabled: false});
}
},
});
//Sets first column to invisible
oTable.fnSetColumnVis(0, false);
}
[/code]
Any help would be greatly appreciated.
Hello, I noticed that my data table is making two request to my server. I decided to debug it with the tool provided and i noticed I am drawing the table twice. Here is my initialization. Has anyone experience similar issue. I am not using the provided php server to process my data if that helps.
UPDATE:I created an alert inside of my fnDrawCallback and i do get 2 alerts. :(
[code]
function buildTable()
{
oTable = $('#example').dataTable({
"bJQueryUI": true,
//"bStateSave": true,
"iDisplayLength": 50,
//"bProcessing": true,
"bServerSide": true,
"bRetrieve": true,
"sAjaxSource": "http://dev1.ocp:8888/server",
"sPaginationType": "full_numbers",
"sDom": 'R<"H"lfr>t<"F"ip<',
"bScrollCollapse": false,
"bAutoWidth": false,
"fnDrawCallback": function(oSettings) {
//Checks for Rows, if empty, disables add row.
//Empty row set oTable.fnSettings().fnRecordsTotal()
if(oTable.fnSettings().aoColumns.length == 1)
{
$("#btn-row-add").button({disabled: true});
}
else
{
$("#btn-row-add").button({disabled: false});
}
},
});
//Sets first column to invisible
oTable.fnSetColumnVis(0, false);
}
[/code]
Any help would be greatly appreciated.
This discussion has been closed.
Replies
"Ah okay - you aren't using server-side processing - which is the trick here... DataTables will actually do a draw before the Ajax data has loaded (I'm wondering if that is actually a bug... I'll bare it in mind and investigate shortly). This first draw occurs during the table's initialisation - which is why you are getting this error. I think the way to solve it is in your fnOpenClose function, simply put a check for "typeof trigger_report_table == 'undefined'" and return if that is the case. Then when the draw occurs for the real data - it will run this function fully."
Here is the link,
http://datatables.net/forums/discussion/57/fndrawcallback/p1
Hope it helps you.
[code]
iTotalDisplayRecords: 14
iTotalRecords: 14
sEcho: 2
[/code]
the 2nd only returns
[code]
iTotalDisplayRecords: 1
iTotalRecords: 14
sEcho: 2
[/code]
That causes a redraw.
[quote]
iTotalDisplayRecords: 1
iTotalRecords: 14
sEcho: 2
[/quote]
Sounds like a problem with the server-side script then. Please post a link to the page so we can confirm that this is the case.
Allan
I just confirmed that oTable.fnSetColumnVis(0, false); causes a redraw. I disabled it and im only drawing once. Is there a way i can hide the first column without causing a redraw?
unfortunately i cannot post a link as any external traffic is blocked. My server is written in node.js
[code]
app.get('/server', function(req, res){
console.log('GET request to /server');
request = req.query;
server(res);
})[/code]
[quote]
Input parameters:
1. {int}: The column whose display should be changed
2. {bool}: Show (true) or hide (false) the column
3. {bool} [default=true]: Redraw the table or not
[/quote]
:-)
Allan
[code]
"aoColumnDefs": [{"bVisible": false, "aTargets": [ 0 ]}],
[/code]