常見的 jQuery 分頁插件多為記憶體分頁,適合資料量小的情境。若資料量龐大,就必須改為服務端分頁,只查詢目前頁面的資料,才能維持效能。
DWZ.init('js/pagination.xml');
$(function () {
$('div.pagination').each(function () {
var $this = $(this);
$this.pagination({
totalCount: $this.attr('totalCount'),
numPerPage: $this.attr('numPerPage'),
pageNumShown: $this.attr('pageNumShown'),
currentPage: $this.attr('currentPage')
});
});
});
當使用者點擊頁碼、切換每頁筆數或跳頁時,會觸發自訂的 PageBreak 函式。開發者可以在其中向後端請求資料,再更新頁面與分頁狀態。