In DT 1.9, fnServerData could return data.iTotalRecords, but in DT 1.10, ajax.dataSrc cannot?

In DT 1.9, fnServerData could return data.iTotalRecords, but in DT 1.10, ajax.dataSrc cannot?

tpditpdi Posts: 4Questions: 2Answers: 1

I want to be able to control what a DataTable thinks the data.iTotalRecords (1.9) / recordsTotal (1.10) is.

In 1.9, it was possible to specify in options a fnServerData, a function which could return this value (along with the actual row data).

In 1.10, when setting option ajax.dataSrc to a function, it appears that function can /only/ return an array of data, not an object containing data and paging metadata.

Without modifying the format the server actually returns, how can I return or set paging metadata in 1.10?

Answers

  • tpditpdi Posts: 4Questions: 2Answers: 1

    Ok, so fnServerData's equivalent in 1.10 is to make ajax /itself/ a function, e.g.:

    $('#someid').DataTable({
    "serverSide" : true,

        "ajax" : function(data, callback, settings) {
            callback({
                "draw" : 1,
                "recordsTotal" : 0,
                "recordsFiltered"  :0,
                "data" :[]
                        })
        }
    }); 
    

    With this, you'll need to manage the whole ajax call yourself, but you can return the metadata,

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    This is correct - thanks for posting your solution.

    Allan

This discussion has been closed.