Skip to content
网游世界
网游世界

吾生有涯,而知无涯。

  • 首页
  • PHP
    • ThinkPHP
    • FastAdmin
    • webman
  • JavaScript
    • jQuery
    • AdminLTE
  • Free Pascal
  • Java
    • JeeSite
    • 若依
    • ruoyi-vue-pro
  • 其它
    • 操作系统
    • 树莓派
    • 前端
    • Null
  • 关于
网游世界

吾生有涯,而知无涯。

Paginationjs 插件 Ajax 请求分页数据

3Vshej, 2023年12月14日 周四2023年12月14日 周四

上一文说到过 Paginationjs 插件简单使用,它只是针对于少量数据。

Paginationjs 插件也支持 Ajax 请求数据。


在使用前,配置2个 div,一个用于展示分页,一个用于展示数据。

如,msg_page 和 msg_list。之后,通过 dataSource 设置请求链接,通过 callback 对这里数据进行处理。

根据需要:通过 alias 配置分页参数别名,locator 指定列表数据属性,totalNumberLocator 设置总记录数。

<!DOCTYPE html>
<html>
<head>
    <title>Paginationjs 插件简单使用</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="http://pagination.js.org/dist/2.6.0/pagination.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        ul, li {
            list-style: none;
        }

        #wrapper {
            width: 900px;
            margin: 20px auto;
        }
    </style>
</head>
<body>

<div id="wrapper">
  <section>

    <div class="msg_page"></div>
    <div class="msg_list"></div>

  </section>
</div>

<script src="http://code.jquery.com/jquery-3.6.1.js"></script>
<script src="http://pagination.js.org/dist/2.6.0/pagination.js"></script>
<script>
$(function() {

    // Ajax 分页
    $('#msg_page').pagination({
        // 配置分页参数别名
        alias: {
            pageNumber: 'pageNo', // 第几页
            pageSize: 'pageSize' // 分页大小
        },
        // 请求地址
        dataSource: '/msg/listData',
        // 响应后,哪个属性是数据项
        locator: 'list',
        // 响应后,获取总记录数
        totalNumberLocator: function (response) {
            return response.count;
        },
        // 分页大小
        pageSize: 6,
        // 配置分页展示效果
        ulClassName: "pagination pagination-sm inline",
        // 分页数据处理
        callback: function (response, pagination) {
            let msgList = [];
            let data;

            msgList.push("<ul class=\"todo-list ui-sortable\">")
            for (const x in response) {
                data = response[x];
                msgList.push("<span>" + data["title"] + "</span>");
            }

            msgList.push("</ul>");

            // 渲染列表
            $("#msg_list").html(msgList.join(""));
        }
    });
</script>
</body>
</html>

相关资源:

  • Pagination.js 官网
  • Pagination.js Github
  • Pagination.js 中文文档

相关文章:

  1. Paginationjs 插件简单使用 在日常工作中,分页很常用,但有时候,不想让后端处理,改为前端 JS 实现分页效果。 前端分页通常适用......
  2. JeeSite 中增加手机固话验证 在 Form 页面输入框类中,增加 contact_phone。...
  3. Layui 表单提交报错 Uncaught TypeError: ‘checkValidity’ called on an object that does not implement interface HTMLButtonElement Layui 表单提交报错: Uncaught TypeError: ‘checkVali......
JavaScript jQuery AjaxjQuery 插件分页插件

文章导航

Previous post
Next post

近期文章

  • Android Studio Gradle 配置国内镜像
  • 为什么重新发明轮子
  • ruoyi-vue-pro 匿名访问
  • VUE 中接收 code 异常
  • 关于 AI

归档

  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 11 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 8 月
  • 2024 年 7 月
  • 2024 年 6 月
  • 2024 年 5 月
  • 2024 年 4 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 12 月
除非特殊说明,本站作品采用知识共享署名 4.0 国际许可协议进行许可。
豫公网安备 41010402002622号 豫ICP备2020029609号-3
©2025 3Vshej