Skip to content

Commit

Permalink
Merge pull request #621 from revolist/column-group-size-preserve
Browse files Browse the repository at this point in the history
fix: preserver column size during column move
  • Loading branch information
revolist authored Nov 4, 2024
2 parents 2df5939 + 49b3fcd commit 558124a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion formats/select
Submodule select updated 1 files
+2 −2 src/editor.ts
2 changes: 1 addition & 1 deletion packages/react
2 changes: 1 addition & 1 deletion packages/vue2
2 changes: 1 addition & 1 deletion packages/vue3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PluginProviders } from '../types/plugin.types';
import type { PluginProviders } from '../types/plugin.types';
import { BasePlugin } from './base.plugin';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export * from './groupingRow/grouping.row.plugin';
export * from './moveColumn/column.drag.plugin';
export * from './sorting/sorting.plugin';
export * from './sorting/sorting.sign';
export * from './add-rows-on-past.plugin';
export * from './add-rows-on-paste.plugin';
21 changes: 14 additions & 7 deletions src/plugins/moveColumn/column.drag.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getItemByPosition } from '@store';
import { BasePlugin } from '../base.plugin';
import { ColumnOrderHandler } from './order-column.handler';
import { dispatch } from '../dispatcher';
import { ColumnPropProp, ColumnRegular, DimensionSettingsState, PositionItem, DimensionCols, MultiDimensionType, PluginProviders } from '@type';
import type { ColumnPropProp, ColumnTemplateProp, DimensionSettingsState, PositionItem, DimensionCols, MultiDimensionType, PluginProviders } from '@type';
import { ON_COLUMN_CLICK } from '../../components/header/header-cell-renderer';
import { isColGrouping } from '../../utils/column.utils';

Expand All @@ -27,7 +27,7 @@ export type DragStartEventDetails = {
type StaticData = {
startPos: number;
startItem: PositionItem;
data: ColumnRegular;
data: ColumnTemplateProp;
dataEl: HTMLElement;
scrollEl: Element;
gridEl: HTMLElement;
Expand Down Expand Up @@ -138,6 +138,11 @@ export class ColumnMovePlugin extends BasePlugin {
const x = getLeftRelative(e.x, this.dragData.gridRect.left, this.dragData.scrollOffset);
const rgCol = getItemByPosition(this.staticDragData.cols, x);
this.orderUi.autoscroll(x, dragData.elRect.width);

// prevent position change if out of bounds
if (rgCol.itemIndex >= this.staticDragData.cols.count) {
return;
}
this.orderUi.showHandler(
rgCol.end + dragData.scrollOffset,
dragData.gridRect.width
Expand All @@ -163,20 +168,22 @@ export class ColumnMovePlugin extends BasePlugin {
const newPosition = getItemByPosition(this.staticDragData.cols, relativePos);

const store = this.providers.column.stores[this.dragData.type].store;
const items = [...store.get('items')];
const newItems = [...store.get('items')];

// prevent position change if needed
const { defaultPrevented: stopDrag } = dispatch(this.revogrid, BEFORE_DRAG_END, {
...this.staticDragData,
startPosition: this.staticDragData.startItem,
newPosition,
newItem: store.get('source')[items[this.staticDragData.startItem.itemIndex]]
newItem: store.get('source')[newItems[this.staticDragData.startItem.itemIndex]]
});
if (!stopDrag) {
const prevItems = [...newItems];
// todo: if move item out of group remove item from group
const toMove = items.splice(this.staticDragData.startItem.itemIndex, 1);
items.splice(newPosition.itemIndex, 0, ...toMove);
store.set('items', items);
const toMove = newItems.splice(this.staticDragData.startItem.itemIndex, 1);
newItems.splice(newPosition.itemIndex, 0, ...toMove);
store.set('items', newItems);
this.providers.dimension.updateSizesPositionByNewDataIndexes(this.dragData.type, newItems, prevItems);
}
dispatch(this.revogrid, DRAG_END, this.dragData);
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/dimension/dimension.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const getItemByPosition = (
positionIndexes,
originItemSize,
positionIndexToItem,
}: DimensionPosition,
}: Pick<DimensionPosition, 'indexes' | 'positionIndexes' | 'originItemSize' | 'positionIndexToItem'>,
pos: number,
) => {
const item: PositionItem = {
Expand Down

0 comments on commit 558124a

Please sign in to comment.