Calling Datatable ajax only on external button click.

Calling Datatable ajax only on external button click.

JDUiJDUi Posts: 2Questions: 1Answers: 0
edited March 20 in DataTables 1.10

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

  • kthorngrenkthorngren Posts: 16,790Questions: 25Answers: 3,979
    Answer ✓

    The sAjaxSource and fnServerData are legacy Datatables options. The current Datatables option for ajax is ajax. You might consider changing to the ajax. More info can be found in the DT 1.9 to 1.10 conversion guide.

    The ajax doesn't get called on page load(

    You have deferRender which keeps Datatables from fetching the data on initialization. Remove it to ajax load the data on initialization.

    but I get an error (invalid Json)

    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

  • JDUiJDUi Posts: 2Questions: 1Answers: 0

    Sir, can you share an example.

  • tangerinetangerine Posts: 3,235Questions: 30Answers: 380

    The place to start is with the troubleshooting steps provided at the link in the error:
    https://datatables.net/manual/tech-notes/1

    Did you do that?

  • kthorngrenkthorngren Posts: 16,790Questions: 25Answers: 3,979

    Here are the server side processing examples.

    Kevin

  • colincolin Posts: 14,448Questions: 1Answers: 2,462

    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

Sign In or Register to comment.