Server side pagination get 0

Server side pagination get 0

SharuruSharuru Posts: 3Questions: 1Answers: 0

Hi, I can get records from server successfully. But pagination can not get such 'recordsFiltered' what it need.
DataTables debugger link is here: http://debug.datatables.net/oqudiq

I think there are something I should do in setting to face my JSON structure, but I can not find similar situation in document :(
dataSrc is set to 'result.record'.

Please help me, thank you.

Answers

  • SharuruSharuru Posts: 3Questions: 1Answers: 0

    Hi there, a tried it again.
    I wrote a function in "dataSrc" like this:

     "dataSrc": function (data) {
                        //console.log(JSON.stringify(data.result));
                        var trimmed = new Object();
                        trimmed.data = data.result.record;
                        trimmed.recordsFiltered = data.result.recordsFiltered;
                        trimmed.recordsTotal = data.result.recordsTotal;
                        trimmed.draw = data.result.draw;
                        console.log(JSON.stringify(trimmed));
                        return trimmed;
                    }
    

    it really returns the structure in http://www.datatables.net/examples/server_side/object_data.html example.

    But it failed, the pagination as well as records are all disappeared.

  • SharuruSharuru Posts: 3Questions: 1Answers: 0

    Finally, I got answer here: https://www.datatables.net/forums/discussion/25079/ajax-datasrc-not-working-as-expected-issue-468-on-github

    I wrote my function like this:

     "dataSrc": function (json) {
                        json.recordsFiltered = json.result.recordsFiltered;
                        json.recordsTotal = json.result.recordsTotal;
                        json.draw = json.result.draw;
                        return json.result.record;
                    }
    

    Is it the best way to do this in this version? (DataTable.js v1.10.7)

This discussion has been closed.