Refresh dataTables data

Refresh dataTables data

big-dealbig-deal Posts: 38Questions: 0Answers: 0
edited December 2010 in General
Hey.

First of all - I love datatables - it's a great solution!

I have a table with a lot of rows - 500 or so.
It is not working - so I have to use a server side processing.
Furthermore, many tables are autorefreshed every certain interval.

I know that xml islands are bad, but I use it and can't undo that at the time being.
Currently, if I am using Dom to add rows to the table body (tblBody.appendChild(row);) and of course when I use xml islands, DataTables doesn't refresh.

How can I make datatables to "rebuild" when I update table date?

Thenks in advanced.

Replies

  • k.anderson3454k.anderson3454 Posts: 1Questions: 0Answers: 0
    This is also my problem. It took me hours to figure it out but I failed.:(
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    If you are using server-side processing, just call fnDraw, which will redraw the table, pulling information from the sever. With client-side processing and an Ajax sourced data set, you can use the fnReloadAjax plug-in: http://datatables.net/plug-ins/api#fnReloadAjax

    Allan
  • big-dealbig-deal Posts: 38Questions: 0Answers: 0
    Thenks Allan.
    But - and correct me if I am wrong, this solution supports only json.
    I use xml, and even xml islands.
    When not using xml islands I am still using xml - parsing the xml element by element, adding each row seperately.

    As I was saying = I parse each td and tr element by element and add them to the table (tblBody.appendChild(row);).
    I do so for historical reasons and for practical reasons - I need to style each td diffrent, depands on its value.

    What can I do?

    thank you.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    There are two options when using XML with DataTables. As you correctly note DataTables doesn't not directly support XML - the reason for this is that a specific XML DTD would need to be defined for DataTables, and it probably wouldn't match what is needed by other systems - hence the plain JS array.

    1. Use fnServerData and the Ajax source options to get your XML and then transpose it into a 2D array and give that to DataTables.

    2. Use the API methods fnClearTable and fnAddData ( http://datatables.net/api ) to clear the table and then add your new data from the XML (again transposed into a JS array).

    Allan
  • smsorensensmsorensen Posts: 8Questions: 0Answers: 0
    Allan,
    I am having a similar issue. I am using the option 2 approach ( fnClearTable and fnAddData) and it clears the data and adds data to the pagination records, but there is no data displaying in the table.

    [code]

    function processNewData(xml){

    var jData = $( xml );

    shipmentSearchResultsTable.fnClearTable();

    var searchResultList = $(jData).find('SearchResultList');
    var searchResults = searchResultList.children();

    searchResults.each(function(){
    var plannedDeliveryDate = $(this).find('plannedDeliveryDate').text();
    var equipment = $(this).find('equipment').text();
    var status = $(this).find('status').text();

    shipmentSearchResultsTable.fnAddData( [
    plannedDeliveryDate,
    equipment,
    status
    ] );

    });
    }

    [/code]
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Are you getting a Javascript error or anything like that? The basic use of fnAddData looks fine to me. I'd suggest adding some debug in to see what is going on.

    Allan
  • smsorensensmsorensen Posts: 8Questions: 0Answers: 0
    No JavaScript errors. I am populating the table when a user submits a search. The first time through the function, everything works. The second time through, the table has some empty table cells and the pagination is displaying the new search results total correctly.
  • anandhsanandhs Posts: 3Questions: 0Answers: 0
    I used the example from smsorensen and got it working, no errors.

    Please let me know if some one wants the code sample.
This discussion has been closed.