Can i rename recordsFiltered or make datattables take the totalElements?

Can i rename recordsFiltered or make datattables take the totalElements?

JanurajJanuraj Posts: 85Questions: 18Answers: 0

the response of the serverside ajax call looks like
{
data: [].
paging: {
count: 10
page: 0
totalElements: 356
totalPages: 36
}
}
but the datatable takes the response in different way with recordsFiltered and recordsTotal

Can i rename it or make datattables take the totalElements?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    That's not the format expected for serverSide. The protocol is discussed here. Also see examples here.

    Cheers,

    Colin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0

    how about the below code:

    $('#myTable').DataTable( {
    serverSide: true,
    ajax: {
    url: '/api/data',
    dataFilter: function(data){
    var json = jQuery.parseJSON( data );
    json.recordsTotal = json.total;
    json.recordsFiltered = json.total;
    json.data = json.list;

            return JSON.stringify( json ); // return JSON string
        }
    

    }
    } );

    wont this thing work for renaming it?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    json.recordsTotal = json.total;
    json.recordsFiltered = json.total;

    Well, that means the count won't work as the filtered count is fixed to the number of records. I would suggest changing the server script to comply with the expectations of the client.

    Or, if you haven't got many records, say less that 50k records, you could remove the serverSide and use client-side processing.

    Colin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0

    Thanks @colin

This discussion has been closed.