Datatables is making two requests to my server [with debug table]

Datatables is making two requests to my server [with debug table]

codemonkcodemonk Posts: 24Questions: 0Answers: 0
edited November 2012 in DataTables 1.9
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.

Replies

  • PrabaOnNetPrabaOnNet Posts: 6Questions: 0Answers: 0
    edited November 2012
    Here is the comment posted by Allan in an older thread

    "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.
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    edited November 2012
    no luck. I found out that the first request returns,

    [code]
    iTotalDisplayRecords: 14
    iTotalRecords: 14
    sEcho: 2
    [/code]
    the 2nd only returns
    [code]
    iTotalDisplayRecords: 1
    iTotalRecords: 14
    sEcho: 2
    [/code]
  • allanallan Posts: 61,928Questions: 1Answers: 10,153 Site admin
    > oTable.fnSetColumnVis(0, false);

    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
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    edited November 2012
    debug: http://debug.datatables.net/obasij

    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]
  • allanallan Posts: 61,928Questions: 1Answers: 10,153 Site admin
    From the fnSetColumnVis documentation ( http://datatables.net/api#fnSetColumnVis ):

    [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]

    :-)
  • allanallan Posts: 61,928Questions: 1Answers: 10,153 Site admin
    Oh - the other thing, if you know you are always going to hide a column, use the bVisible option - its much more efficient.

    Allan
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    Sorry to get back so late(vacation), thank you for your help, I've should have looked more deeply into the API reference. Your help doesn't go unnoticed in this community, thanks. for anyone with similar issue, I've adopted allan's suggestion:

    [code]
    "aoColumnDefs": [{"bVisible": false, "aTargets": [ 0 ]}],
    [/code]
This discussion has been closed.