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.

242 lines (241 loc) 6.8 kB
import { ValidateError } from 'async-validator'; import type CellHeader from './CellHeader'; import type Context from './Context'; import type { ChangeItem, Column, FilterMethod, Position, EVirtTableOptions, SpanInfo } 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 checkboxKeyMap; private originalDataMap; private changedDataMap; private validationErrorMap; private itemRowKeyMap; private bufferData; private sumHeight; private filterMethod; private positions; constructor(ctx: Context, options: EVirtTableOptions); init(): 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): any; /** * 根据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): Promise<void>; /** *设置单一数据 * @param rowKey * @param key * @param value * @param history 是否添加历史记录 * @param reDraw 是否刷新重绘 * @param isEditor 是否是编辑器 * @returns */ setItemValue(rowKey: string, key: string, _value: any, history?: boolean, reDraw?: boolean, isEditor?: 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): void; getSelectionRows(): any[]; /** * 根据rowKey 获取选中状态 * @param rowKey */ getRowSelection(rowKey: string): any; /** * 根据rowKey 获取选中状态 * @param rowKey */ getRowSelectable(rowKey: string): any; /** * 全选 * @param rowKey */ toggleAllSelection(): void; /** * 清除选中 * @param rowKey */ clearSelection(): void; /** * 获取选中状态,表头用 * @param rowKey */ getCheckedState(): { check: boolean | 0; indeterminate: boolean | 0; selectable: boolean; }; /** * 更新列索引 * @param list 表头末级列表 */ updateColIndexKeyMap(list?: CellHeader[]): void; getColumnByColIndex(colIndex: number): Column | 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: any[]): void; clearValidationError(rowKey: string, key: string): void; getValidationError(rowKey: string, key: string): ValidateError[]; getVirtualBodyCell(rowIndex: number, colIndex: number): Cell | undefined; hasMergeCell(xArr: number[], yArr: number[]): boolean; }