Load more button
Load more button
I have been scouring the web trying to find an elegant solution and have not been able to find anything on the subject but we have an ajax source for our data, I want to make a load more button at the bottom of the page and once the button is pressed it loads 'x' more results from the server and appends it to the end of the table. We need to use an ajax source to still have the ability to search our database without having to load all results to our page everytime.
What I've tried:
I have an ajax function that submits info to our backend and returns a correctly formed JSON array with the exact data I want: 'x' records starting one element after our last in the table. What I do not know is how to append this to the current table. I've tried sending the results to the table using fnAddData(json.aaData, true) or fnAddData(json.aaData, false) followed by fnDraw() it looks like it works correctly but my network tab in chrome developer tools shows me that two ajax calls are returning, one that I made with the correct info and one that datatables made which pull all the results already on the table+'x' new results. I need to know how to prevent datatables from making the sequential call (I imagine part of fnDraw() ) and how to append my results (JSON) to the end of the table. Any suggestions?
This might help: ehejaq (datatables debug)
What I've tried:
I have an ajax function that submits info to our backend and returns a correctly formed JSON array with the exact data I want: 'x' records starting one element after our last in the table. What I do not know is how to append this to the current table. I've tried sending the results to the table using fnAddData(json.aaData, true) or fnAddData(json.aaData, false) followed by fnDraw() it looks like it works correctly but my network tab in chrome developer tools shows me that two ajax calls are returning, one that I made with the correct info and one that datatables made which pull all the results already on the table+'x' new results. I need to know how to prevent datatables from making the sequential call (I imagine part of fnDraw() ) and how to append my results (JSON) to the end of the table. Any suggestions?
This might help: ehejaq (datatables debug)
This discussion has been closed.
Replies
fnAddData is a client-side function - it is useless when you have server-side processing enabled. As the documentation for it says:
> Please note that this is suitable for client-side processing only - if you are using server-side processing (i.e. "bServerSide": true), then to add data, you must add it to the data source, i.e. the server-side, through an Ajax call.
Perhaps the new documentation for 1.10 might help: http://next.datatables.net/manual/data#Processing-modes .
Allan
Also have you heard of any 'load more button' versions of datatables created by the community? I've been searching alot but have not been able to find anything?
That is correct. That is how server-side processing operates. The data for every draw must be retrieved from the server. That is how it is designed to operate and how it does.
> Also have you heard of any 'load more button' versions of datatables created by the community?
A load more button doesn't make sense with server-side processing to be honest. If you want to show more data, redraw the table with a larger display length.
With client-side processing, then it is as trivial as you initially suggest, just use fnAddData .
Allan