layui数据表格增加序号列(第二页从1开始 or 接上一页序号开始)

layui数据表格增加序号列:


一.分页模式下第二页从1开始


1、在table.render()方法中,加

{title: '序号', align: "center",templet: '#indexTpl'},

示例:

table.render({
                elem: '#goods',
                url: '/index',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.count, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };
                }
                , page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'],//自定义分页布局
                    limits: [10, 20, 50, 100],
                    limit: 10,
                },
                where: {
                    messageOrNotice: 1
                }
                , skin: 'line' //line(行边框风格)row (列边框风格)nob (无边框风格)
                , cols: [[
                   {title: '序号', align: "center", templet: '#indexTpl'},
                    {field: 'title', title: '标题', align: "center"},
                    {field: 'content', title: '消息内容', align: "center", toolbar: '#barDemo1'},
                    {field: 'sendTime', title: '发送时间', align: "center", templet:
                            function (d) {
                                return formatDate(d.sendTime);
                            }
                    },
                ]],

            });
<script type="text/html" id="indexTpl">
    {{d.LAY_TABLE_INDEX+1}}
</script>

2.利用thymeleaf

通过后端传过来的list循环取得数据

th:text="${orderStat.count}"

index:当前迭代对象的index(从0开始计算)
count: 当前迭代对象的index(从1开始计算)

示例:

		<div class=" order">
            <div class="orderTop">
                <ul class="clear">
                    <li>序号</li>
                    <li>、、、</li>
                </ul>
            </div>
            <div th:each="order,orderStat : ${list}">
                <div class="orderDetail">
                    <ul class="clear">
                        <li>
                            <span th:text="${orderStat.count}"></span>
                        </li>
                        <li class="w60">
                           、、、、、、、
                        </li>
                    </ul>
                </div>
            </div>
        </div>

二、第二页的序号接着第一页的开始


1.在table.render()方法中,加

{title: '序号', align: "center",type:"numbers"},

示例:

table.render({
                elem: '#goods',
                url: '/index',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.count, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };
                }
                , page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'],//自定义分页布局
                    limits: [10, 20, 50, 100],
                    limit: 10,
                },
                where: {
                    messageOrNotice: 1
                }
                , skin: 'line' //line(行边框风格)row (列边框风格)nob (无边框风格)
                , cols: [[
                   {title: '序号', align: "center", type: "numbers"},
                    {field: 'title', title: '标题', align: "center"},
                    {field: 'content', title: '消息内容', align: "center", toolbar: '#barDemo1'},
                    {field: 'sendTime', title: '发送时间', align: "center", templet:
                            function (d) {
                                return formatDate(d.sendTime);
                            }
                    },
                ]],

            });

2.利用thymeleaf

通过后端传过来的list,循环取得数据

th:text="${(page-1) * size + orderStat.count}"

(当前页-1)*每页多少条 + 当前迭代对象的index(从1开始)
比如:每页10条,第二页第二条数据应该是12.
(2-1)*10+2 = 12

示例:

<div class=" order">
	<div class="orderTop">
		<ul class="clear">
			<li>序号</li>
			<li>、、、</li>
		</ul>
	</div>
	<div th:each="order,orderStat : ${list}">
		<div class="orderDetail">
			<ul class="clear">
				<li>
					<span th:text="${(page-1) * size + orderStat.count}"></span>
				</li>
				<li class="w60">
					、、、、、、、
				</li>
			</ul>
		</div>
	</div>
</div>
<input hidden id="pageCount" th:value="${count}">
<input hidden id="pageSize" th:value="${size}">
<input hidden id="pageCurr" th:value="${page}">

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值