Custom data source property dataSrc and pagination issue

前端 未结 1 1385
予麋鹿
予麋鹿 2020-12-09 21:11

I\'m working with jQuery DataTables and server-side processing mode. But I\'m facing an issue with data table, I\'ve search every thing in Datatables documentation but could

相关标签:
1条回答
  • 2020-12-09 22:04

    CAUSE

    In server-side processing mode DataTables expects certain structure in returned data. Parameters draw, recordsTotal and recordsFiltered should be top-level properties. You response has these parameters as sub-properties of data, not where DataTables would be looking for them.

    SOLUTION

    Set parameters draw, recordsTotal and recordsFiltered as top-level properties of JSON response where DataTables expects them to be.

    Use the following code for ajax.dataSrc option:

    dataSrc: function(json){
       json.draw = json.data.draw;
       json.recordsTotal = json.data.recordsTotal;
       json.recordsFiltered = json.data.recordsFiltered;
    
       return json.data.data;
    }
    

    DEMO

    See this jsFiddle for code and demonstration.

    0 讨论(0)
提交回复
热议问题