Cannot display with latest data after ajax call
Cannot display with latest data after ajax call

I have Search button which not a part of table.
When I click on Seatch button, the ajax call will be called and returned json data format.
It's okie to use api to display data
success: function(data, status) {
var datatable = $('#transactions_tb').DataTable();
result = jQuery.parseJSON(data)
datatable.clear();
datatable.rows.add(result.data);
datatable.rows().data().length=0
datatable.draw();
},
But in case the "serverSide": true, the display not work. Can you please give me an idea to fix the issue. Thank you and appreciate.
This discussion has been closed.
Answers
Do you have
serverSide: true
configured? If so then using an external ajax call is not how server side processing works. This doc explains the protocol:https://datatables.net/manual/server-side
If using server side processing then you should use the
search()
API for the search. Doing this will use the server side protocol, assuming your server script conforms to the protocol.What are you trying to do with this line?
Can you post an example of what is returned, copied from the browser's developer tools?
Do you get alert messages or errors in your browser's console?
What is your Datatables config?
Kevin
I tried with many solution but unlucky.
The return data having format as:
It works when serverSide = false. So I think when serverSide is set to true, we need to bind the parameters such as recordsTotal. recordsFiltered to datatable. I tried but not work.
Many example binding data from initialization of table. My case is external and should use api to bind data. It's really rare example about that.
Server Side Processing does not work with
rows.add()
. Once you usedraw()
Datatables will send a request to the server for the current page. Using a separate ajax call won't work with server side processing. You will probably see two ajax requests with your click event; one that is from the ajax request in the function and one that is from Datatables.My suggestion is to use
ajax.data
as a function to send the parameters you have in your separate ajax request. The docs have an example. The response will need to be in the format that server side processing supports.You can then simply use
draw()
in the click event function. You may need to add an additional parameter that is a flag to control whether to use the parameters sent or to use normal Datatables processing in your server script.Kevin
Thanks for your valuable answer.
My case is call external ajax when Search button click and bind data again to table. Is it possible on this case when serverSide is True?
So can you please give me a details example about that?
I think when we use external ajax call, we have to use api to binding again to datatable.
Unfortunately I don't have a server side script I can build an example from. But I think you will want to do something close to this:
I'm not sure what the
dataFilter
function is doing. Doesn't look like it is changing anything.You will need to work out a way to tell the server script whether to use the normal SSP processing or to use the parameters set in the data function.
Kevin