feat(table): 新增 table.updateRow方法 (#1540)

* feat(table): 新增 `table.updateRow` 方法

* refactor

* update code

* update doc

* feat(table): 新增 `table.updateTotalRow`

* perf(table): 改进 updateRow 渲染性能

* feat(table): col.totalRow 支持函数,改进 updateTotalRow 参数

* feat(table): 新增 table.getTotalRow

* feat(table): table.getTotalRow 支持获取原始结果

* perf(table): 改进 table.updateRow 性能

* fix: 修复 updateRow  一些问题

* revert: 回退除 table.updateRow 以外的所有改动

REVERT:
bc61f9ff08d4e512585b399c0dd41954c3878bd0
1a5258b292c6b67873df35f456883afd3da04cbb
4af5b1cda4d2ce6049f7dfafb25f99a498196bc4
62e551d22bfc8a379c15ce44f290f7ff73dbcb3a
这些方法互相关联,而 totalRow 存在暂时无法解决的问题,故全部回退。后续在其他 PR 中实现。

* refactor(table): updateRow options.row 重命名为 options.data
This commit is contained in:
morning-star
2024-01-18 13:10:49 +08:00
committed by GitHub
parent 3bced33798
commit 90000f39f6
2 changed files with 116 additions and 36 deletions

View File

@@ -28,6 +28,7 @@ toc: true
| [table.reload(id, options, deep)](#table.reload) | 表格完整重载。 |
| [table.reloadData(id, options, deep)](#table.reloadData) <sup>2.7+</sup> | 表格数据重载。 |
| [table.renderData(id)](#table.renderData) <sup>2.8.5+</sup> | 重新渲染数据。 |
| [table.updateRow(id, opts)](#table.updateRow) <sup>2.9.4+</sup> | 更新指定行数据。 |
| [table.checkStatus(id)](#table.checkStatus) | 获取选中行相关数据。 |
| [table.setRowChecked(id, opts)](#table.setRowChecked) <sup>2.8+</sup> | 设置行选中状态。 |
| [table.getData(id)](#table.getData) | 获取当前页所有行表格数据。 |
@@ -313,6 +314,41 @@ data.splice(newIndex, 0, item[0]);
table.renderData('test');
```
<h3 id="table.updateRow" lay-pid="api" class="ws-anchor ws-bold">更新指定行数据 <sup>2.9.4+</sup></h3>
`table.updateRow(id, opts);`
- 参数 `id` : table 渲染时的 `id` 属性值
- 参数 `opts` : 更新指定行时的可选属性,详见下表
| opts | 描述 | 类型 | 默认值 |
| --- | --- | --- | --- |
| index | 行索引 | number | - |
| data | 行数据 | object | - |
| related | 是否更新其他包含自定义模板且可能有所关联的列视图 | boolean/function | - |
该方法用于更新指定行数据。
```js
// 渲染
table.render({
elem: '', // 绑定元素选择器
id: 'test', // 自定义 id 索引
// 其他属性 …
});
// 更新指定行数据
table.updateRow('test', {
index: 0,
data: {
id: 1,
username: 'name'
}
// 是否更新关联的列视图
related: function(field, index){
return ['score', '5'].indexOf(field) !== -1;
}
});
```
<h3 id="table.checkStatus" lay-pid="api" class="ws-anchor ws-bold">获取选中行</h3>