iter(g324): table-core 补 setColumns,换列后失效排序与筛选剔除
This commit is contained in:
@@ -210,4 +210,42 @@ clamp.dispatch({ type: 'setPage', page: 9 }); // 显式跳到越界页
|
||||
assert(clamp.getVisibleRows().rows.length === 1 && clamp.getState().pagination.page === 3, '跳越界页:派生钳制后回写为末页 3');
|
||||
assert(clamp.getPageInfo().totalPages === 3, '收敛不改分页快照语义(totalPages 仍按 total 推算)');
|
||||
|
||||
// setColumns:动态换列,失效的排序 / 筛选按 key 剔除,accessor 跟随新列集
|
||||
const colsTable = createTable({
|
||||
data: users,
|
||||
columns: [
|
||||
{ key: 'name', header: 'Name', sortable: true },
|
||||
{ key: 'age', header: 'Age', sortable: true, accessor: (row) => row.age },
|
||||
{ key: 'city', header: 'City' },
|
||||
],
|
||||
rowKey: 'id',
|
||||
plugins: [filterPlugin(), sortPlugin(), paginationPlugin(), selectionPlugin()],
|
||||
initialState: {
|
||||
sorting: [{ key: 'age', dir: 'desc' }],
|
||||
filters: [{ key: 'city', value: 'Beijing' }],
|
||||
},
|
||||
});
|
||||
assert(colsTable.getVisibleRows().total === 2, 'setColumns 前:city 筛选生效(Beijing 2 行)');
|
||||
colsTable.setColumns([
|
||||
{ key: 'name', header: 'Name', sortable: true },
|
||||
{ key: 'score', header: 'Score', accessor: (row) => 100 - row.age }, // 换列集:city 列没了,age 列换成派生 score
|
||||
]);
|
||||
assert(
|
||||
colsTable.getState().sorting.length === 0 && colsTable.getState().filters.length === 0,
|
||||
'setColumns 后:指向不存在列的排序 / 筛选整体剔除(age 列已换成 score)',
|
||||
);
|
||||
assert(colsTable.getVisibleRows().total === 5, 'setColumns 后:失效筛选被剔除,total 回到全量 5 行');
|
||||
assert(colsTable.getColumns().length === 2 && colsTable.getColumns()[1].key === 'score', 'setColumns 后:getColumns 返回新列集');
|
||||
assert(
|
||||
colsTable.getCellValue(users[0], 'score') === 65,
|
||||
'setColumns 后:getCellValue 跟随新列 accessor(score = 100 - age)',
|
||||
);
|
||||
const sameCols = colsTable.getColumns();
|
||||
let colNotified = 0;
|
||||
colsTable.subscribe(() => {
|
||||
colNotified += 1;
|
||||
});
|
||||
colsTable.setColumns(sameCols);
|
||||
assert(colNotified === 0, 'setColumns 引用未变:短路不通知');
|
||||
|
||||
console.log('SMOKE OK');
|
||||
|
||||
Reference in New Issue
Block a user