How to set correct recordTotal in client side

How to set correct recordTotal in client side

maabomaabo Posts: 7Questions: 3Answers: 0

Dear,

I get the following response from the server with correct data and recordTotal (I use a a pagination in server side).

The service : http://localhost:8080/rest/ListPaginate?length=10&start=0

In DB I have 6543 and for pagination I show for the first page 0

    var table = $('#tableList').DataTable({
        "ajax": {
            "type": "POST",
            "url": "rest/ListPaginate",
            'data': {
                start: function () { return param.start },
                length: function () { return param.length }
            },
            "dataSrc": function (json) {
                //Make your callback here.
                setTableWithFailedProcess(json["data"]);
                return json["data"];
            }
        },
        "columns": [
            { data: 'id' },
            { data: 'name' },
            { data: 'Message' },
            { data: 'trace' },
            { data: 'timestamp' }
        ],
        language: {
            emptyTable: "<li class='text-danger' align='center'>NUSE não encontrada</li>",
            paginate: {
                previous: "<",
                next: ">",
                first: "|<",
                last: ">|"
            }
        }
    });

// Response from my server
{
    "data": [
        {
            "id": 677,
            "name": "proc1",
            "message": "enpoint",
            "trace": "Exception: ",
            "timestamp": 1648046677828
        },
         .....
        {
            "id": 726,
            "name": "proc1",
            "message": "enpoint",
            "trace": "Exception: ",
            "timestamp": 1648046677828
        }
    ],
    "recordsTotal": 6543
}

But I notice that, in the client side, I have not the correct recodsTotal setted :
I got Showing 1 to 10 of 10 entries ..

Why 10 entries instead 6543 ? And how to set the correct value

Answers

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    You haven't enabled server side processing by setting the serverSide option to true. Datatables will automatically supply the start and lengh paramters so you won't need to set them using this:

                'data': {
                    start: function () { return param.start },
                    length: function () { return param.length }
                },
    

    Kevin

Sign In or Register to comment.