Calling Datatable ajax only on external button click.
Calling Datatable ajax only on external button click.
JDUi
Posts: 2Questions: 1Answers: 0
I have 2 parameters and depending on that I need data in the data table. I'll use click to fill the data table.
The ajax doesn't get called on page load(no error in console of browser), but I get an error (invalid Json) on reload function call and my server method doesn't gets called. I'll need to call server side code for sorting, paging and searching. Kindly help.
My code
$(table).DataTable({
serverSide:true,
sAjaxSource:Controller/Action,
fnServerData:function(){
},
deferLoading:0
});
$(button).click(function()
{
$(table).DataTable().ajax.reload();
});
This question has an accepted answers - jump to answer
Answers
The
sAjaxSource
andfnServerData
are legacy Datatables options. The current Datatables option for ajax isajax
. You might consider changing to theajax
. More info can be found in the DT 1.9 to 1.10 conversion guide.You have
deferRender
which keeps Datatables from fetching the data on initialization. Remove it to ajax load the data on initialization.Th e place to start is with the troubleshooting steps provided at the link in the error:
https://datatables.net/manual/tech-notes/1
Let us know what you find.
Kevin
Sir, can you share an example.
Did you do that?
Here are the server side processing examples.
Kevin
For server-side processing, the protocol is discussed here. Also see examples here. If you download the DataTables repo, there are examples of the server-side scripts in
/examples/server_side/scripts
,Cheers,
Colin