简体   繁体   中英

Pagination doesn't work with DataTables 1.10.7 / 1.10.11

I'm trying to enable server-side processing for data-tables and searching/sorting/chaning amount of rows work, everything except pagination

The setup for datatables is like this:

$('[data-table]').each(function() {
    var url = $(this).data("table");
    $(this).DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": {
            url: url,
            type: 'POST'
        }
    });
})

Server side, the response looks like this:

{
    data: […]
    draw: "12"
    recordsFiltered: 10
    recordsTotal: "208"
}

This is the result: 没有分页

And the funny thing is, if I ommit recordsFiltered and recordsTotal pagination work (kinda, last dosent work, but the rest does)... check these images:

分页没有总数

您只有10行,因此只有1页就没有分页。

"recordsTotal" and "recordsFiltered" should be the same value. So, if you have 160 total records in your table or query, yo should set the same value to the "recordsFiltered" parameter.

This is a common misunderstanding, according to the docs. What the docs says and i think we all understand is that we should filter the records and set the "recordsFiltered" this count.

"Total records, after filtering (ie the total number of records after filtering has been applied - not just the number of records being returned for this page of data)."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM