AJAX table load, server calls pileup

AJAX table load, server calls pileup

josemotajosemota Posts: 17Questions: 0Answers: 0
edited September 2011 in DataTables 1.8
Hi everyone, I have a pretty odd situation here. Simply put:
* I load many tables via AJAX.
* Each of these table loads has its own set of different columns settings.
* When each of the tables is loaded, a common trigger goes off and powers the table with DT (server-side on).

The problem: The stack of server calls piles up for each new table load.
The question would be: How can I clear the calls trace from table to table?

Thanks for the help, guys. Let me know if you need any more info.

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Hi josemota,

    I'm afraid I'm not quite sure I 100% understand. For every table you create with server-side processing enabled, you'll get an Ajax request made to the server to get the data for each draw. So if you have 10 server-side processing tables initially, you'll get 10 Ajax requests. Is that what you are concerned about?

    One possible solution to this would be to make your own single Ajax call and then return the data for all 10 (or however many) tables and populate them using the fnAddData API method. This would doesn't really allow for server-side processing though (it's possible, but a little "trickery" would be needed, since feature switching typically isn't supported). How many rows are we talking about in the tables. If it's less than 10000 (with deferred rendering enabled) then this approach would work okay.

    Allan
  • josemotajosemota Posts: 17Questions: 0Answers: 0
    Hi Allan, I'll try to make myself a little clearer, it really is tricky:

    1. Consider a page layout. It doesn't have any tables whatsoever.
    2. After the page is loaded,
    2.1. I do an AJAX call to fetch the table layout and boot Datatables with `aoColumns` to set the columns' definitions, which then fetches the actual table data.
    3. There's a button somewhere that allows me to repeat step 2.1.
    4. What I acknowledged from this is each time I ask for a new table layout, the table data number of calls stacks up. If I repeated step 2.1. ten times, I would have 10 table data calls for the table that's rendered.

    I hope this will help to understand better. Thanks for helping, Allan!
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    I think I get the general idea, but I don't quite understand the issue still. What is it that would would prefer to happen rather than another Ajax call for each table?

    Allan
  • josemotajosemota Posts: 17Questions: 0Answers: 0
    I wanted it to be only one call, since there's only one table displayed.

    Technically speaking, I need to find some sort of array or loop that executes the AJAX call within DT.
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Can you not just make the Ajax call yourself and then feed the data to DataTables like this: http://datatables.net/release-datatables/examples/data_sources/js_array.html

    Allan
  • josemotajosemota Posts: 17Questions: 0Answers: 0
    I wish :P Sadly, the data comes from an external service API which we don't control. Metadata for the table on one side, tabular data on the other.

    I understand this example is really complex and I will try and post a video with a concrete scenario, with a sample test for you to see, would that be good?

    Thanks for investing the time.
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Yes that would be helpful, as I don't think I fully "get it" yet I'm afraid :-)

    Allan
  • josemotajosemota Posts: 17Questions: 0Answers: 0
    Hi everyone, I figured this problem out. Let me explain what happened.

    1. I was triggering custom events from the body, for when I had all the data coming from the server needed to boot the table.
    2. Everytime I requested a new table setup, the trigger was pulled from the body. Somehow the trigger pull count kept stacking up.
    3. The solution came down to switching the element that pulled the trigger, from the body to the table itself. Therefore, every time I requested a new table setup, the older would be destroyed and with it all the previous trigger bindings, garanteeing that only one AJAX call is performed.

    It was a pretty nasty insect. Watch out for those triggers.

    A huge thanks to Pedro Pinheiro (http://twitter.com/ppinheir8) for helping me out.
This discussion has been closed.