Datatable Not Sorting After Ajax Call

Datatable Not Sorting After Ajax Call

kmcnetkmcnet Posts: 5Questions: 2Answers: 0

Hello everyone and thanks for your help in advance. I am new to datatable. I am populating at datatable with JSON data from a WebAp2 controller. I have the datatable populating correctly, however, all of the sort and search functionalities stopped working. Additionally, the paging buttons show multiple pages even though I am currently only returning 4 records. Here is my code:
'''
$('#myAjaxTable').DataTable(
{
"processing": true,
"serverSide": true,
"sortable": true,
"ajax": "../api/Claim/GetUnpaidClaims",

                "columns": [

                    { "data": "MRNumber" },
                    { "data": "FirstName" },
                    { "data": "LastName" },
                    { "data": "DOB" }


                ]

            }
            );

    });

'''
I am assuming this has to do with the DOM of the table being populated after the datatable is declared, but I am not sure how to fix this. Any help would be appreciated.

Replies

  • pingcrosbypingcrosby Posts: 29Questions: 4Answers: 1

    When your running serverside its up to you to do the sorting/paging etc.

    You must also return the correct data - eg recordsTotal etc..

    Read this link https://datatables.net/manual/server-side

    In particular look at what the server is supposed to return.

        "draw": 1,                 
        "recordsTotal": 57,   /// this determines the no. of records that datatables will think
        "recordsFiltered": 57,
    
    

    etc

This discussion has been closed.