Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change parameter name in datatable.net such as : "draw", "recordsTotal" , "recordsFiltered"

I use PagingAndSortingRepository of Spring framework for my app. When Page interface in server response to client with parameter: totalPages, totalElements, numberOfElements,size. But client datatable jquery (datatable.net) needs draw, recordsTotal , recordsFiltered parameters. Please help me to resolve this problem.

like image 766
Hùng Ng Vi Avatar asked Dec 24 '22 13:12

Hùng Ng Vi


1 Answers

Use the ajax.dataSrc callback for preprocessing the response :

$('#example').dataTable( {
  serverSide: true,
  ajax: {
    url: "path/to/server",
    dataSrc: function(json) {
       json['recordsTotal'] = json['totalElements'];
       json['recordsFiltered'] = json['numberOfElements'];
       return json;
    }
  }
});
like image 122
davidkonrad Avatar answered Jan 13 '23 13:01

davidkonrad