2014-05-09 60 views
2

使用iTotalRecords與過濾iTotalDisplayRecords似乎不與分頁和表顯示長度工作jQuery的數據表過濾分頁

這裏是我的DataTable的js代碼:

transTable.dataTable({ 
    "aaSorting": [[0,"desc"]], 
    "sPaginationType": "full_numbers", 
    "bJQueryUI": true, 
    "aLengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]], 
    "iDisplayLength": 10, 
    "bProcessing": true, 
    "bServerSide": true, 
    "sAjaxSource": "", 
    "sServerMethod": "POST" 
    "aoColumns": [ 
     { "mData": "datetime"}, 
     { "mData": "trans"}, 
     { "mData": "type"} 
    ] 
}); 

當我第一次加載JSON(只發布到同一頁面),分頁工作和正確顯示與排序一樣。每頁我的默認顯示的是10

然而,當我使用過濾器的搜索框,有關post數據是:

{ ... 
    iDisplayStart: 0 
    iDisplayLength: 10 
    sSearch: searchText 
    ... 
} 

的SQL查詢運行是:

SELECT 
* 
FROM 
trans 
WHERE 
    (type LIKE "%searchText%") OR 
    (trans_id LIKE "%searchText%") OR 
    (datetime LIKE "%searchText%") 
ORDER BY "datetime" DESC 
LIMIT 10 -- 0 is iDisplayStart so no OFFEST set here and 10 is iDisplayLength 

我的JSON響應是這樣的:

{ 
    'aaData': [the query result rows], 
    'iTotalRecords: 10000, //total number of records in the table 
    'iTotalDisplayRecords: 10, 
    'sEcho': //POST params "sEcho" value 
} 

因爲在查詢上有一個限制10,iTotalDisplayRecords將是10

你會認爲分頁會顯示「顯示1到10條1,234條記錄(從10,000條過濾),並允許分頁通過1,234條記錄(123頁)。但不是。它說:「顯示1到10條10,000條記錄」,沒有分頁。

如果我擺脫iDisplayLength的,分頁文字看起來正確,分頁工作正常,但該表顯示了所有1,234記錄,不只是10

我在做什麼錯?

回答

0

IIRC,iTotalDisplayRecords應該是篩選集合(1,234)的一部分記錄數。

我通過在我的sql中使用輸出參數來設置我的分頁數據表來計算我的數據庫中的記錄總數(10,000)和過濾結果的數量(1,234),然後在我的json中傳遞它(與數據一起和繪製次數)分別爲iTotalRecords和iTotalDisplayRecords。

Screenshot of implementation