iter(g247): 表格支持整体换数据源,dataTable 可接信号数据
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { effect, type Signal } from '@ui-arch/frame';
|
||||
import type { RowKey, TableInstance } from '@ui-arch/table-core';
|
||||
|
||||
/*** 作用:取数据源当前值——传数组直接返回,传信号 / computed 则调用取值(表格创建时用) ***/
|
||||
export function readRows<T>(data: T[] | Signal<T[]>): T[] {
|
||||
return typeof data === 'function' ? data() : data;
|
||||
}
|
||||
|
||||
/*** 作用:给表格挂换源 effect——数据源是信号时信号变化即整体换源,静态数组直接返回(不多挂 effect、不多算一次派生) ***/
|
||||
export function attachDataSource<T extends { id: RowKey }>(
|
||||
table: TableInstance<T>,
|
||||
data: T[] | Signal<T[]>,
|
||||
): void {
|
||||
if (typeof data !== 'function') return; // 卫语句:静态数组无需响应式换源
|
||||
const source = data;
|
||||
effect(() => table.setRows(source())); // setRows 内部按 rowKey 剔除失效选择项,页码与排序保持原意
|
||||
}
|
||||
Reference in New Issue
Block a user