Any way to get the *next* ajax parameters?

Any way to get the *next* ajax parameters?

crwdzrcrwdzr Posts: 31Questions: 5Answers: 6
edited September 2017 in Free community support

I'm doing a lot of server-side processing and am using something along these lines under the "ajax" option:

"data" : defaultArgs => getArgs(defaultArgs),

which takes the default datatables Ajax arguments(draw, length, columns, etc) and then mixes in more custom arguments for my server-side script(date ranges, etc) in a different function.

I have some custom code in my script so that when you click a row it highlights it and allows a user to interact, it's basically my own version of the editor. When you change pages it keeps track of where the row is and when you change the filters, like the date ranges, it automatically re-centers onto the page of the active row. My issue is that in order to properly perform a lookup to find out what page the row will be on, I have to send the current search parameters to the server and the only way I know to get ALL of them is to do something like:

reload with table.ajax.reload, then as a callback to that query the server with the desired row ID and the last ajax parameters, then as a callback to that run table.page(page #).draw(false)

that ends up being 3 requests, and I can't help but feel that very first one can be removed...

I'm using the jQuery 2.2.4/DataTables 1.10.15 bundle.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    You can get the current Ajax parameters using ajax.params() which will include any custom filtering information (since its basically just a reference to the object that was sent to the server with the last request).

    However you can't get the next set of parameters because you can't know a priori what will change in the next request (the user might change the page, or they might filter, etc).

    I might be wrong, but it sounds like you could use ajax.params() to get the current parameters instead of using ajax.reload().

    Allan

  • crwdzrcrwdzr Posts: 31Questions: 5Answers: 6
    edited September 2017

    I've been thinking about this a bit backwards :#

    You are absolutely correct, ajax.params() will work afterall.. since datatables auto-reloads any time its default ajax arguments would change, I don't need the table to return to me what they will be for the next request in my situation (because they would be the same) and I just have to read those and re-add my custom arguments (which are ones that may have changed prior to the manual re-load that is about to happen due to their changing)

This discussion has been closed.