UNPKG

e-virt-table

Version:

A powerful data table based on canvas. You can use it as data grid、Microsoft Excel or Google sheets. It supports virtual scroll、cell edit etc.

249 lines (248 loc) 7.25 kB
import type CellHeader from './CellHeader'; import { ValidateResult } from './Validator'; import type Context from './Context'; import type { ChangeItem, Column, FilterMethod, Position, EVirtTableOptions, SpanInfo, HistoryAction } from './types'; import Cell from './Cell'; export default class Database { private loading; private ctx; private data; private columns; private footerData; private rowKeyMap; private colIndexKeyMap; private headerMap; private rowIndexRowKeyMap; private rowKeyRowIndexMap; private checkboxKeyMap; private selectionMap; private expandMap; private originalDataMap; private changedDataMap; private validationErrorMap; private itemRowKeyMap; private bufferData; private bufferCheckState; private sumHeight; private filterMethod; private positions; constructor(ctx: Context, options: EVirtTableOptions); init(isClear?: boolean): void; /** * 清除缓存数据 */ clearBufferData(): void; /** * 初始化数据 * @param dataList * @param level */ private initData; /** * * @param rowKey 设置Row高度 * @param height */ setRowHeight(rowIndex: number, height: number): void; /** * * @returns 获取转化平铺数据 */ getAllRowsData(): any[]; private filterColumns; getColumns(): Column[]; setColumns(columns: Column[]): void; setData(data: any[]): void; /** * 统一转化数据,给画body使用,包括过滤树状等,统一入口 * @returns */ getData(): { data: any[]; sumHeight: number; positions: Position[]; }; setFooterData(data: any[]): void; getFooterData(): any[]; /** * 设置过滤方法 */ setFilterMethod(filterMethod: FilterMethod): void; /** * 清空过滤方法 */ clearFilterMethod(): void; /** * 根据rowKey,控制指定展开行 * @param rowKey * @param expand */ expandItem(rowKey: string, expand?: boolean): void; setExpandRowKeys(rowKeys: any[], expand?: boolean): void; getExpandRowKeys(): string[]; expandAll(expand: boolean): void; expandLoading(rowKey: string, loading?: boolean): void; setExpandChildren(rowKey: string, children: any[]): void; getIsExpandLoading(rowKey: string): any; getIsExpandLazy(rowKey: string): any; /** * 根据rowKey获取是否展开 * @param rowKey * @returns */ getIsExpand(rowKey: string): any; /** * 根据rowKey获取行数据 * @param rowKey * @returns */ getRowForRowKey(rowKey: string): any; getRowForRowIndex(rowIndex: number): any; /** * 根据rowIndex获取rowKey * @param rowKey * @returns */ getRowKeyForRowIndex(rowIndex: number): string; getRowKeyByItem(item: any): any; getRowIndexForRowKey(rowKey: string): number | undefined; /** * 根据rowIndex和colIndex获取单元格数据 * @param rowIndex * @param colIndex * @returns */ getItemValueForRowIndexAndColIndex(rowIndex: number, colIndex: number): { rowKey: string; key: string; value: any; } | null; /** * 根据rowKey和key获取单元格数据 * @param rowKey * @param key * @returns */ getItemValue(rowKey: string, key: string): any; /** * 批量设置数据 * @param list * @param history * @returns */ batchSetItemValue(_list: ChangeItem[], history?: boolean, checkReadonly?: boolean, historyAcion?: HistoryAction): Promise<void>; /** *设置单一数据 * @param rowKey * @param key * @param value * @param history 是否添加历史记录 * @param reDraw 是否刷新重绘 * @param isEditor 是否是编辑器 * @param checkReadonly 是否检查只读 * @returns */ setItemValue(rowKey: string, key: string, _value: any, history?: boolean, reDraw?: boolean, isEditor?: boolean, checkReadonly?: boolean): Promise<{ oldValue?: undefined; newValue?: undefined; } | { oldValue: any; newValue: any; }>; /** * 根据rowKey 获取行数据 * @param rowKey * @returns */ getRowDataItemForRowKey(rowKey: string): any; /** * * @param rowKey 设置选中状态ByCheckboxKey,用于合并Checkbox单元格时声明唯一key * @param check */ private setRowSelectionByCheckboxKey; /** * 根据rowKey 取反选中 * @param rowKey */ toggleRowSelection(rowKey: string): void; /** * 根据rowKey 设置选中状态 * @param rowKey */ setRowSelection(rowKey: string, check: boolean, draw?: boolean): void; getSelectionRows(): any[]; /** * 根据rowKey 获取选中状态 * @param rowKey */ getRowSelection(rowKey: string): boolean; /** * 根据rowKey 获取选中状态 * @param rowKey */ getRowSelectable(rowKey: string): any; /** * 全选 * @param rowKey */ toggleAllSelection(): void; /** * 清除选中 * @param rowKey */ clearSelection(ignoreReserve?: boolean): void; /** * 获取选中状态,表头用 * @param rowKey */ getCheckedState(): { check: boolean; indeterminate: boolean; selectable: boolean; }; /** * 更新列索引 * @param list 表头末级列表 */ updateColIndexKeyMap(list?: CellHeader[]): void; getColumnByColIndex(colIndex: number): Column | undefined; getColumnByKey(key: string): CellHeader | undefined; getColIndexForKey(key: string): number | undefined; getColHeaderByIndex(colIndex: number): CellHeader | undefined; /** * 获取以改变数据 */ getChangedData(): { rowKey: string; colKey: string; row: any; originalValue: any; value: any; }[]; getChangedRows(): any[]; /** * 获取改变值是否已经改变 * @param rowKey * @param key * @returns */ isHasChangedData(rowKey: string, key: string): boolean; getPositionForRowIndex(rowIndex: number): Position; setHeader(key: string, cellHeader: CellHeader): boolean; getReadonly(rowKey: string, key: string): any; clearValidate(): void; hasValidationError(): boolean; getValidator(rowKey: string, key: string): Promise<unknown>; getHeightByRowIndexRowSpan(rowIndex: number, rowSpan: number): number; getSpanInfo(cell: Cell): SpanInfo; setLoading(loading: boolean): void; getLoading(): boolean; setValidationErrorByRowIndex(rowIndex: number, key: string, message: string): void; setValidationError(rowKey: string, key: string, errors: ValidateResult): void; clearValidationError(rowKey: string, key: string): void; getValidationError(rowKey: string, key: string): ValidateResult; getVirtualBodyCell(rowIndex: number, colIndex: number): Cell | undefined; getVirtualBodyCellByKey(rowKey: string, key: string): Cell | undefined; hasMergeCell(xArr: number[], yArr: number[]): boolean; }