new API (draw(), clear() and ajax.reload())

new API (draw(), clear() and ajax.reload())

logeloge Posts: 15Questions: 1Answers: 0
edited July 2014 in DataTables 1.10

Hi,

i have a ajax backed table. Now when i click a button, i want to clear the table and reload stuff and show it. Easy enough.
My problem is that clear() doesnt work without draw() at the end. But draw() does the ajax call itself. So i cant show the user an empty table while its reloading.

I dont get why draw() reloads the ajax source. I thought that ajax.reload() is responsible for that.

At the end i only want to temporary clear the table, while the ajax request is being made so that the user doesnt see the "old" data in the meantime. Sounds easy but somehow i am missing something....

Thanks
Marc

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I dont get why draw() reloads the ajax source.

    Sounds like you have server-side processing enabled. Do you (a debug trace or a link to the page would be useful)?

    If so, then yes, a draw() will always trigger a reload. Also clear() won't empty the table since it is a client-side function.

    You might want to read over the processing modes part of the manual.

    Allan

  • logeloge Posts: 15Questions: 1Answers: 0

    server side processing is on. yes. I will read the stated docs. Thanks.

  • logeloge Posts: 15Questions: 1Answers: 0

    Ok. I am familiar with the infos in the docs so far. But back to my question. Is there any easy way to clear the table (visually) after i have called a draw() for reloading?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    How long does the reload take - 200mS perhaps? Why not just show a "processing" message (processing).

    Allan

  • logeloge Posts: 15Questions: 1Answers: 0

    I am already showing the processing message, but anyway... i might live with it... Not a serious issue... just something i ve been thinking about. I thought i ve missed something obvious... but seems not...

    thx.

  • andy_250andy_250 Posts: 3Questions: 1Answers: 0

    I have similar issue actually: I have an ajax-based datatable, which I want to "expand" when user scrolls the browser window. I am able to fetch more data on scroll (e.g. fetch 20 more rows after scroll is bigger than 70% of page height) and add it with rows.add(...). However after calling .draw() the table gets reloaded to original state (an ajax call is executed) - ending up with first 20 rows only displayed. Is there any way to add rows and re-draw them without doing full ajax reload?

  • andy_250andy_250 Posts: 3Questions: 1Answers: 0

    Solved it. This post lead me to solution:

    http://datatables.net/forums/discussion/6580/fnadddata-not-working-as-expected

    Simply I don't use datatables API when appending new rows loaded from server. Instead I only append all <tr> from the ajax response to the DOM.

This discussion has been closed.