layui/examples/treeTable-test-reloadData.html
caji 627dc8b738
fix(treeTable): 修复重载数据时,指定参数 scrollPos: 'fixed' 无效的问题 (#1892)
* 修正treeTable重载数据时,指定参数 scrollPos: 'fixed' ,
无法实现保持滚动条在原有位置的问题。

* 1,把修改代码移动到Class.prototype.render方法体中; 2,把let修改为var

* 修改let->var

* Update src/modules/treeTable.js

Co-authored-by: morning-star <26325820+Sight-wcg@users.noreply.github.com>

* Update src/modules/treeTable.js

Co-authored-by: morning-star <26325820+Sight-wcg@users.noreply.github.com>

* 按照评审人给出的修改意见进行修改

主要修改点:
1,通过给done包装函数设置scrollPosPatch标志位,避免重复包装;
2,包装后的done函数执行完毕后,恢复原来的done函数,避免以后再次触发done函数时,仍然执行保持滚动条位置的逻辑;

* 函数调用时,call->apply

* refactor: 简化代码

1. 将修复代码迁移至 updateOptions
2. table done 回调第四个参数,现在可以区分 reloadData 和 renderData

---------

Co-authored-by: morning-star <26325820+Sight-wcg@users.noreply.github.com>
2024-05-17 19:13:01 +08:00

73 lines
2.0 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>树形表格 - layui</title>
<link rel="stylesheet" href="../src/css/layui.css">
</head>
<body class="layui-padding-5">
<table class="layui-hide" id="test"></table>
<script type="text/html" id="TPL-treeTable-demo">
<div class="layui-btn-container">
<a class="layui-btn layui-btn-sm" lay-event="reloadData">重载数据</a>
</div>
</script>
<script src="../src/layui.js"></script>
<script>
layui.use(['treeTable', 'dropdown', 'layer'], function(){
var treeTable = layui.treeTable;
var dropdown = layui.dropdown;
var layer = layui.layer;
// 渲染
var inst = treeTable.render({
elem: '#test',
url: './json/treeTable/demo-1.json',
maxHeight: '700px',
toolbar: '#TPL-treeTable-demo',
tree: {
customName: {
name: 'name'
},
view: {
iconLeaf: ''
}
},
cols: [[
{type: 'checkbox', fixed: 'left'},
{type: 'numbers', fixed: 'left'},
{field: 'id', title: 'ID', width: 145, sort: true, fixed: 'left', totalRow: '合计:'},
{field: 'name', title: '用户名', width: 180, fixed: 'left'},
{field: 'experience', title: '积分', width: 90, sort: true},
{field: 'sex', title: '性别', width: 80, sort: true},
{field: 'score', title: '评分', width: 80, sort: true},
{field: 'city', title: '城市', width: 150},
{field: 'description', title: '描述', minWidth: 200},
{field: 'createTime', title: '创建时间', width: 170},
]],
page: true
});
// 表头工具栏工具事件
treeTable.on('toolbar('+ inst.config.id +')', function (obj) {
var config = obj.config;
var tableId = config.id;
var status = treeTable.checkStatus(tableId);
if (obj.event === "reloadData") {
treeTable.reloadData(tableId, {
scrollPos: 'fixed'
});
}
});
});
</script>
</body>
</html>