Multple AJAX requests - change ajax url on render
Multple AJAX requests - change ajax url on render
Hi
I've just switched over our front end to use DataTables.js + scroller and I'm loving it so far.
Only one small problem with it that I can see:
In order to get different results on load, we are managing our searching in the front end.
e.g
example.com/sales/{offset}/{length}/?SortBy=Price&Age=6
example.com/sales/0/100/?SortBy=Price&Age=6
Is there a way to make scroller load the next set of data from a different ajax url?
So if I want to have the table render 100 records at a time and before rendering more records send another ajax request to:
example.com/sales/100/100/?SortBy=Price&Age=6
The ajax that the datatable requests currently loads in one large json as a workaround.
Thanks
Answers
Hi,
I think what you'd have to do for this, since they are query string parameters, but part of the address, you'd need to use
ajax
as a function and then make your own Ajax call based on the information that DataTables is requesting.There isn't a way for DataTables to embed its parameters into the address at the moment. Although I like that idea. Thanks for the suggestion!
Allan
No problems allan. My manager was pushing for this method and it seems like it could be a good investment for Datatables.
Referring to my own ajax call, what would be the event before loading new data on scroller load? What would be the information that Datatables requests?
Thanks!
You won't need to listen for an event if you use
ajax
as a function. It will be called automatically whenever DataTables needs more data.Allan
At the moment it seems to make one big ajax call to get all 10000+ records and renders them at once, which is painfully slow.
Is there a way to deferRender these rows with a dynamic / non-fixed table height? So that I'm able to use a fixedHeader as well?
Yes,
deferRender
should help speed things up assuming you have paging enabled (or use Scroller if you need it to be a scrolling view).However, if you don't want to load all of the records at the same time,
serverSide
is the way to do that.Allan