mirror of
https://github.com/VisActor/VTable
synced 2024-11-22 01:52:03 +00:00
fix: add event and config in column/row move
This commit is contained in:
parent
9b79733fea
commit
6c556232b7
@ -41,6 +41,10 @@ export interface TableEvents {
|
||||
* 鼠标点击表格事件
|
||||
*/
|
||||
MOUSEDOWN_TABLE: 'mousedown_table';
|
||||
/**
|
||||
* 鼠标在表格上移动事件
|
||||
*/
|
||||
MOUSEMOVE_TABLE: 'mousemove_table';
|
||||
/**
|
||||
* 鼠标在某个单元格上移动事件
|
||||
*/
|
||||
@ -77,6 +81,7 @@ export interface TableEvents {
|
||||
* 拖拽表头移动位置的事件
|
||||
*/
|
||||
CHANGE_HEADER_POSITION: 'change_header_position';
|
||||
CHANGE_HEADER_POSITION_START: 'change_header_position_start';
|
||||
/**
|
||||
* 点击排序图标事件
|
||||
*/
|
||||
@ -180,6 +185,7 @@ export const TABLE_EVENT_TYPE: TableEvents = {
|
||||
MOUSEENTER_TABLE: 'mouseenter_table',
|
||||
MOUSELEAVE_TABLE: 'mouseleave_table',
|
||||
MOUSEDOWN_TABLE: 'mousedown_table',
|
||||
MOUSEMOVE_TABLE: 'mousemove_table',
|
||||
MOUSEMOVE_CELL: 'mousemove_cell',
|
||||
MOUSEENTER_CELL: 'mouseenter_cell',
|
||||
MOUSELEAVE_CELL: 'mouseleave_cell',
|
||||
@ -188,6 +194,7 @@ export const TABLE_EVENT_TYPE: TableEvents = {
|
||||
RESIZE_COLUMN_END: 'resize_column_end',
|
||||
RESIZE_ROW: 'resize_row',
|
||||
RESIZE_ROW_END: 'resize_row_end',
|
||||
CHANGE_HEADER_POSITION_START: 'change_header_position_start',
|
||||
CHANGE_HEADER_POSITION: 'change_header_position',
|
||||
SORT_CLICK: 'sort_click',
|
||||
FREEZE_CLICK: 'freeze_click',
|
||||
|
@ -41,6 +41,20 @@ export function bindTableGroupListener(eventManager: EventManager) {
|
||||
// if (stateManager.interactionState === InteractionState.scrolling) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 触发MOUSEMOVE_TABLE
|
||||
if (eventArgsSet.eventArgs && (table as any).hasListeners(TABLE_EVENT_TYPE.MOUSEMOVE_TABLE)) {
|
||||
table.fireListeners(TABLE_EVENT_TYPE.MOUSEMOVE_TABLE, {
|
||||
col: eventArgsSet.eventArgs.col,
|
||||
row: eventArgsSet.eventArgs.row,
|
||||
x: eventArgsSet.abstractPos.x,
|
||||
y: eventArgsSet.abstractPos.y,
|
||||
event: e.nativeEvent,
|
||||
target: eventArgsSet?.eventArgs?.target,
|
||||
mergeCellInfo: eventArgsSet.eventArgs?.mergeInfo
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
stateManager.interactionState === InteractionState.grabing &&
|
||||
!(table as ListTableAPI).editorManager?.editingEditor
|
||||
|
@ -31,7 +31,7 @@ export function handleWhell(event: FederatedWheelEvent, state: StateManager, isW
|
||||
state.setScrollTop(state.scroll.verticalBarPos + optimizedDeltaY, event);
|
||||
state.showVerticalScrollBar(true);
|
||||
}
|
||||
isWheelEvent && state.resetInteractionState();
|
||||
isWheelEvent && state.resetInteractionState(state.interactionStateBeforeScroll);
|
||||
if (
|
||||
event.nativeEvent?.cancelable &&
|
||||
(state.table.internalProps.overscrollBehavior === 'none' ||
|
||||
|
@ -116,7 +116,8 @@ export function endMoveCol(state: StateManager): boolean {
|
||||
state.columnMove.colSource >= 0 &&
|
||||
state.columnMove.rowSource >= 0 &&
|
||||
state.columnMove.colTarget >= 0 &&
|
||||
state.columnMove.rowTarget >= 0
|
||||
state.columnMove.rowTarget >= 0 &&
|
||||
state.table.options.customConfig?.notUpdateInColumnRowMove !== true
|
||||
) {
|
||||
//getCellMergeInfo 一定要在moveHeaderPosition之前调用 否则就不是修改前的range了
|
||||
const oldSourceMergeInfo = state.table.getCellRange(state.columnMove.colSource, state.columnMove.rowSource);
|
||||
|
@ -62,6 +62,7 @@ export class StateManager {
|
||||
* Scrolling 滚动中
|
||||
*/
|
||||
interactionState: InteractionState;
|
||||
interactionStateBeforeScroll?: InteractionState;
|
||||
// select记录两个位置,第二个位置只在range模式生效
|
||||
select: {
|
||||
ranges: (CellRange & { skipBodyMerge?: boolean })[];
|
||||
@ -189,8 +190,8 @@ export class StateManager {
|
||||
|
||||
radioState: Record<string | number, boolean | number | Record<number, number>> = {};
|
||||
// 供滚动重置为default使用
|
||||
resetInteractionState = debounce(() => {
|
||||
this.updateInteractionState(InteractionState.default);
|
||||
resetInteractionState = debounce((state?: InteractionState) => {
|
||||
this.updateInteractionState(state ?? InteractionState.default);
|
||||
}, 100);
|
||||
// _x: number = 0;
|
||||
constructor(table: BaseTableAPI) {
|
||||
@ -528,6 +529,12 @@ export class StateManager {
|
||||
if (this.interactionState === mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode === InteractionState.scrolling) {
|
||||
this.interactionStateBeforeScroll = this.interactionState;
|
||||
}
|
||||
|
||||
// console.log('updateInteractionState', mode);
|
||||
const oldState = this.interactionState;
|
||||
this.interactionState = mode;
|
||||
// 处理mode 更新后逻辑
|
||||
@ -797,6 +804,7 @@ export class StateManager {
|
||||
|
||||
startMoveCol(col: number, row: number, x: number, y: number) {
|
||||
startMoveCol(col, row, x, y, this);
|
||||
this.table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_START, { col, row, x, y });
|
||||
}
|
||||
updateMoveCol(col: number, row: number, x: number, y: number) {
|
||||
updateMoveCol(col, row, x, y, this);
|
||||
|
@ -492,6 +492,9 @@ export interface BaseTableConstructorOptions {
|
||||
createReactContainer?: boolean;
|
||||
// adaptive 模式下优先缩小迷你图
|
||||
shrinkSparklineFirst?: boolean;
|
||||
|
||||
// 行列移动不更新表格
|
||||
notUpdateInColumnRowMove?: boolean;
|
||||
}; // 部分特殊配置,兼容xTable等作用
|
||||
|
||||
animationAppear?: boolean | IAnimationAppear;
|
||||
|
@ -67,6 +67,7 @@ export interface TableEventHandlersEventArgumentMap {
|
||||
mouseenter_table: { event?: MouseEvent | PointerEvent | TouchEvent };
|
||||
mouseleave_table: { event?: MouseEvent | PointerEvent | TouchEvent };
|
||||
mousedown_table: { event?: MouseEvent | PointerEvent | TouchEvent };
|
||||
mousemove_table: MousePointerCellEvent;
|
||||
mouseenter_cell: MousePointerCellEvent;
|
||||
mouseleave_cell: MousePointerCellEvent;
|
||||
mousemove_cell: MousePointerCellEvent;
|
||||
@ -107,6 +108,7 @@ export interface TableEventHandlersEventArgumentMap {
|
||||
resize_row: { row: number; rowHeight: number };
|
||||
resize_row_end: { row: number; rowHeight: number };
|
||||
change_header_position: { source: CellAddress; target: CellAddress };
|
||||
change_header_position_start: { col: number; row: number; x: number; y: number };
|
||||
sort_click: {
|
||||
field: FieldDef;
|
||||
order: SortOrder;
|
||||
@ -211,6 +213,7 @@ export interface TableEventHandlersReturnMap {
|
||||
mouseenter_table: void;
|
||||
mouseleave_table: void;
|
||||
mousedown_table: void;
|
||||
mousemove_table: void;
|
||||
mouseenter_cell: void;
|
||||
mouseleave_cell: void;
|
||||
// mouseover_cell: void;
|
||||
@ -228,6 +231,7 @@ export interface TableEventHandlersReturnMap {
|
||||
resize_row: void;
|
||||
resize_row_end: void;
|
||||
change_header_position: void;
|
||||
change_header_position_start: void;
|
||||
sort_click: boolean;
|
||||
freeze_click: void;
|
||||
dropdown_menu_click: void;
|
||||
|
Loading…
Reference in New Issue
Block a user