Rename recordsTotal and recordsFiltered

Rename recordsTotal and recordsFiltered

pdugaspdugas Posts: 13Questions: 4Answers: 2

It is possible to change the name DT is using to look for these fields in AJAX responses?

This question has an accepted answers - jump to answer

Answers

  • javawxljavawxl Posts: 1Questions: 0Answers: 0

    hi , do you solution it?

  • pdugaspdugas Posts: 13Questions: 4Answers: 2
    Answer ✓

    So the forums stop bugging me to accept an answer... The fix was to pre-process the returned data to rename them.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Yes - that's the correct answer :). At the moment the server-side processing parameter names are not configurable. Yet...

    Allan

  • bryan_g8bryan_g8 Posts: 1Questions: 0Answers: 0

    I found the solution! Use the dataFilter function.

    $('#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
            }
       }
    } );
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Very nice - thanks for sharing that with is.

    Allan

This discussion has been closed.