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}">