iter(g247): 表格支持整体换数据源,dataTable 可接信号数据
This commit is contained in:
@@ -172,4 +172,25 @@ assert(
|
||||
);
|
||||
assert(all.getPageInfo().totalPages === 1, 'getAllRows 不影响分页快照(2 行 / 每页 2 = 1 页)');
|
||||
|
||||
// setRows:整体换数据源,选择状态按 rowKey 剔除失效行,页码越界由插件收敛
|
||||
const swapped = createTable({
|
||||
data: users,
|
||||
columns: [{ key: 'name', header: 'Name' }],
|
||||
rowKey: 'id',
|
||||
plugins: [selectionPlugin(), paginationPlugin()],
|
||||
initialState: { pagination: { page: 1, pageSize: 2 } },
|
||||
});
|
||||
swapped.dispatch({ type: 'toggleSelect', key: 1 }); // 选中两行,后面验证失效行被剔除
|
||||
swapped.dispatch({ type: 'toggleSelect', key: 4 });
|
||||
assert(swapped.isRowSelected(1) && swapped.isRowSelected(4), 'setRows 前:两行已选');
|
||||
swapped.setRows(users.filter((u) => u.id !== 4));
|
||||
assert(swapped.getVisibleRows().total === 4, 'setRows 后:total 跟随新数据(5 行 → 4 行)');
|
||||
assert(swapped.isRowSelected(1) && !swapped.isRowSelected(4), 'setRows 后:失效行键从选择里剔除,有效行保留');
|
||||
assert(swapped.getState().pagination.page === 1, 'setRows 不动页码(用户翻页意图不被打断)');
|
||||
const sameRows = users.filter((u) => u.id !== 4);
|
||||
let notified = 0;
|
||||
swapped.subscribe(() => (notified += 1));
|
||||
swapped.setRows(sameRows);
|
||||
assert(notified === 1 && swapped.getVisibleRows().total === 4, 'setRows 换引用:通知一次并重算 total');
|
||||
|
||||
console.log('SMOKE OK');
|
||||
|
||||
Reference in New Issue
Block a user