angularjs结合layui分页指令

var app = angular.module('qingwei', ['ui.router', 'oc.lazyLoad']);
app.directive('myPage', function() {
    return {
        restrict: 'AE',
        scope: {
            tableData: '=',
            currentPageData: '='
        },
        link: function(scope, element, attr) {
            scope.clickPage = false;
            scope.$watch('tableData', function (newVal, oldVal) {
                if (newVal == oldVal) {
                    return;
                }
                layer.load(1);
                renderPage();
            }, true);
            function renderPage() {
                laypage.render({
                    elem: attr.id //注意,这里的 test1 是 ID,不用加 # 号
                    ,count: scope.tableData.length //数据总数,从服务端得到
                    ,limit : 10
                    ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                    ,jump: function(obj, first) {
                        //当前页
                        var currentPage = obj.curr;
                        //每页显示条数
                        var limit = obj.limit;
                        scope.currentPageData = getCurrentData(currentPage, limit, scope.tableData.length);
                        if(!scope.$$phase && !scope.$root.$$phase){
                            scope.$apply();
                        }
                        layer.closeAll();
                    }
                });
            }

            /**
             * @param currentPage 当前页码
             * @param pageSize 每页size
             * @param total 总数
             * @returns {string}
             */
            function getCurrentData(currentPage, pageSize, total) {
                var currentPage = parseInt(currentPage);
                var total = parseInt(total);
                var from = (currentPage - 1) * pageSize;
                var to = from + pageSize;
                //边界处理
                if (from <= 0) {
                    from = 0;
                    to = from + pageSize;
                    if (to > total) {
                        to = total;
                    }
                }
                if (to > total) {
                    from = to - pageSize;
                    to = total;
                    if (from <= 0) {
                        from = 0;
                    }
                }
                return scope.tableData.slice(from, to);
            }
        }
    };
})

 

<my-page table-data="blackheadFileList" id="mytable"  current-page-data="currentPageData"></my-page>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,关于 layui 分页表格,您需要在页面引入 layui 的相关文件,然后通过 layui 的表格和分页模块实现。您可以参考以下代码示例: ```html <!-- 引入 layui 相关文件 --> <link rel="stylesheet" href="/layui/css/layui.css"> <script src="/layui/layui.js"></script> <!-- 在页面中添加一个表格容器 --> <table id="table" lay-filter="table"></table> <!-- 在 JavaScript 中配置表格和分页模块 --> <script> layui.use(['table', 'laypage'], function(){ var table = layui.table; var laypage = layui.laypage; // 配置表格数据和列信息 table.render({ elem: '#table', url: '/api/data', cols: [[ {field: 'id', title: 'ID', width: 80}, {field: 'name', title: '姓名', width: 120}, {field: 'age', title: '年龄', width: 80}, {field: 'gender', title: '性别', width: 80}, {field: 'address', title: '地址', width: 200}, {field: 'phone', title: '电话', width: 120} ]], page: true, limit: 10 }); // 配置分页 laypage.render({ elem: 'page', count: 100, limit: 10, layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'], jump: function(obj, first){ // obj包含当前分页的所有参数,如: // { // curr: 1, // 当前页码 // limit: 10, // 每页显示的条数 // ... // } // first表示是否首次渲染分页 if(!first){ // 非首次渲染分页时,重新加载表格数据 table.reload('table', { where: { page: obj.curr, limit: obj.limit } }); } } }); }); </script> ``` 在上面的代码中,我们首先引入了 layui 的相关文件,然后在页面中添加了一个表格容器。接着,在 JavaScript 中配置了表格数据和列信息,并启用了分页功能。最后,我们使用 layui分页模块来渲染分页,并在分页回调函数中重新加载表格数据。 需要注意的是,上面的代码只是一个示例,具体的实现方式可能会根据您的需求而有所不同。您可以根据自己的实际情况进行调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

裂魂人1214

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值