0

我有一个大型数据库表,我想向用户展示。我在表格中显示信息,每页大约 30 行。我想使用 jqPagination 来允许用户跳转到不同的页面。所以第 1 页将显示第 1-30 行,第 2 页将显示第 31-60 行,... 我看到的唯一示例是展示如何使用它跳转到页面的不同部分。是否可以使用 jqPagination 来请求新页面的下 30 行?

提前致谢!

4

1 回答 1

0

如果您要显示所有表格行,则可以使用以下代码一次仅显示 30 行:

$(document).ready(function() {

    // select the table rows
    $table_rows = $('.table-example tbody tr');

    var table_row_limit = 30;

    var page_table = function(page) {

        // calculate the offset and limit values
        var offset = (page - 1) * table_row_limit,
            limit = page * table_row_limit;

        // hide all table rows
        $table_rows.hide();

        // show only the n rows
        $table_rows.slice(offset, limit).show();

    }

    $('.pagination').jqPagination({
        max_page: $table_rows.length / table_row_limit,
        paged: page_table
    });

    // set the initial table state to page 1
    page_table(1);

});

表格分页示例

如果您一开始不显示所有行,则可以调整此代码以使用 AJAX 从系统中获取行,而不是显示/隐藏。

于 2013-12-08T18:25:29.223 回答