Data is shown twice inside datatabels - double amount of rows

Data is shown twice inside datatabels - double amount of rows

crscrs Posts: 3Questions: 0Answers: 0
edited October 2011 in General
Hi all!
I have the following problem:

I have a server generated json object with 2 rows of data.
But for some non repeatable reason it sometimes occurs that 4 rows are displayed in datatables.
The amount of rows is simply doubled.
Look here: http://img33.imageshack.us/img33/6199/datatwotimes.png

This is what happens on my web-page:

[code]
/** There is NEW data available....**/
newVal=$_GET['newVal'];
oTable = $('#myTable').dataTable( {
...
"sAjaxSource": "getData.php?x="+newVal
...
});
/** because the table won't refresh its data **/
oTable.fnReloadAjax();
[/code]

now... SOMETIMES the double amount of datarows is shown.
why? how can i prevent datatbels of doing this?

Hope you understood my problem, thanks in advance!

//christina

Replies

  • AnthonyVAnthonyV Posts: 37Questions: 7Answers: 0
    edited July 2012
    I was running into the same problem and found that my initial page load (with the ajax calls to get data) were colliding with the request to get fresh data via fnReloadAjax();

    I resolved it by calling [oTable.oApi._fnClearTable(oTable.fnSettings());] inside my [fnServerData] method just prior to [fnCallback].

    The best solution is to ensure that [fnReloadAjax()] is not callable until after your page and all the tables are fully loaded.

    [code]
    "fnServerData": function (sSource, aoData, fnCallback) {
    $.ajax({
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function (data, textStatus, jqXHR)
    {
    oTable.oApi._fnClearTable(oTable.fnSettings());
    fnCallback(data, textStatus, jqXHR);
    }
    });
    }
    [/code]
This discussion has been closed.