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.
319 lines (318 loc) • 9.76 kB
TypeScript
import type CellHeader from './CellHeader';
import { ValidateResult } from './Validator';
import type Context from './Context';
import type { ChangeItem, Column, FilterMethod, Position, EVirtTableOptions, SpanInfo, HistoryAction, CustomHeader, Fixed } from './types';
import Cell from './Cell';
export default class Database {
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 customHeader;
overlayerAutoHeightMap: Map<string, number>;
private maxRowHeightMap;
private bufferCheckState;
private sumHeight;
private filterMethod;
private positions;
private sortState;
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;
setBatchRowHeight(rowIndexHeightList: {
rowIndex: number;
height: number;
}[]): void;
setBatchCalculatedRowHeight(rowIndexHeightList: {
rowIndex: number;
height: number;
}[]): void;
/**
* 清除最大行高记录
*/
clearMaxRowHeight(): void;
/**
* 获取所有行数据(平铺)
* @returns 获取转化平铺数据
*/
getAllRowsData(): any[];
private generateColumns;
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;
/**
* 获取排序状态
*/
getSortState(key: string): import("./types").SortStateMapItem;
/**
* 设置排序状态
*/
setSortState(key: string, direction: 'asc' | 'desc' | 'none'): void;
/**
* 清除所有排序状态
*/
clearSort(): void;
/**
* 递归排序方法,支持树形数据
* @param data 要排序的数据
* @param sortedEntries 排序条目,按时间戳排序
* @returns 排序后的数据
*/
private sortDataRecursive;
/**
* 对数组进行单列排序
* @param data 要排序的数据
* @param key 排序的列键
* @param direction 排序方向
* @param sortBy 排序类型
* @returns 排序后的数据
*/
private applySingleColumnSort;
/**
* 根据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, cellType?: string): void;
toggleTreeSelection(rowKey: string): void;
private selectTreeSelectionRecursive;
private clearTreeSelectionRecursive;
private updateParentTreeSelection;
/**
* 根据rowKey 设置选中状态
* @param rowKey
*/
setRowSelection(rowKey: string, check: boolean, draw?: boolean): void;
setRowSelectionByParent(rowKey: string, check: boolean): void;
getSelectionRows(): any[];
/**
* 根据rowKey 获取选中状态
* @param rowKey
*/
getRowSelection(rowKey: string): boolean;
getTreeSelectionState(rowKey: string): {
checked: boolean;
indeterminate: boolean;
};
getTreeChildren(rowKey: string): string[];
getTreeParent(rowKey: string): string | null;
/**
* 根据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;
setValidationErrorByRowKey(rowKey: string, 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, isUpdate?: boolean): Cell | undefined;
getVirtualBodyCellByKey(rowKey: string, key: string): Cell | undefined;
hasMergeCell(xArr: number[], yArr: number[]): boolean;
/**
* 计算树形数据的最大深度
* @param data 树形数据
* @param currentDepth 当前深度
* @returns 最大深度
*/
private calculateMaxTreeDepth;
setOverlayerAutoHeightMap(map: Map<string, number>): void;
getOverlayerAutoHeightMap(): Map<string, number>;
getOverlayerAutoHeight(rowIndex: number, colIndex: number): number;
setCustomHeader(customHeader: CustomHeader, ignoreEmit?: boolean): void;
resetCustomHeader(): void;
getCustomHeader(): CustomHeader;
setCustomHeaderResizableData(key: string, width: number): void;
setCustomHeaderHideData(keys: string[], hide: boolean): void;
setCustomHeaderFixedData(keys: string[], fixed: Fixed | ''): void;
clearCustomHeaderInvalidValues(columns: Column[]): CustomHeader;
clearChangeData(): void;
}