Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 Table 的 columns-toggler 中列拖拽排序逻辑错误 #11616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/amis-ui/src/locale/de-DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ register('de-DE', {
'Table.copyRow': 'Zeile kopieren',
'Table.columnsVisibility':
'Klicken, um die Sichtbarkeit der Spalten zu steuern',
'Table.columnsSorting': 'Spalte ziehen, um zu sortieren',
'Table.deleteRow': 'Aktuele Zeile löschen',
'Table.discard': 'Verwerfen',
'Table.dragTip': 'Schaltfläche links zum Sortieren ziehen',
Expand Down
1 change: 1 addition & 0 deletions packages/amis-ui/src/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ register('en-US', {
'Table.subAddRow': 'Add sub row',
'Table.copyRow': 'Copy row',
'Table.columnsVisibility': 'Click to control columns visibility',
'Table.columnsSorting': 'Drag column to sort',
'Table.deleteRow': 'Delete current row',
'Table.discard': 'Discard',
'Table.dragTip': 'Drag the button on the left to sort',
Expand Down
1 change: 1 addition & 0 deletions packages/amis-ui/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ register('zh-CN', {
'Table.subAddRow': '新增孩子',
'Table.copyRow': '复制一行',
'Table.columnsVisibility': '点击选择显示列',
'Table.columnsSorting': '拖拽列修改显示顺序',
'Table.deleteRow': '删除当前行',
'Table.discard': '放弃',
'Table.dragTip': '请拖动左边的按钮进行排序',
Expand Down
30 changes: 9 additions & 21 deletions packages/amis/src/renderers/Table/ColumnToggler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ export default class ColumnToggler<
});
}

swapColumnPosition(oldIndex: number, newIndex: number) {
const columns = this.state.tempColumns;
moveColumn(oldIndex: number, newIndex: number) {
const columns = [...this.state.tempColumns];

columns[oldIndex] = columns.splice(newIndex, 1, columns[oldIndex])[0];
columns.splice(newIndex, 0, columns.splice(oldIndex, 1)[0]);
this.setState({tempColumns: columns});
}

Expand Down Expand Up @@ -266,23 +266,8 @@ export default class ColumnToggler<
handle: `.${ns}ColumnToggler-menuItem-dragBar`,
ghostClass: `${ns}ColumnToggler-menuItem--dragging`,
onEnd: (e: any) => {
if (e.newIndex === e.oldIndex) {
return;
}

const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

this.swapColumnPosition(e.oldIndex, e.newIndex);
if (e.newIndex === e.oldIndex) return;
this.moveColumn(e.oldIndex, e.newIndex);
}
}
);
Expand Down Expand Up @@ -389,10 +374,13 @@ export default class ColumnToggler<
contentClassName={cx('ColumnToggler-modal')}
container={modalContainer || this.target}
overlay={typeof overlay === 'boolean' ? overlay : false}
draggable={true}
>
<header className={cx('ColumnToggler-modal-header')}>
<span className={cx('ColumnToggler-modal-title')}>
{__('Table.columnsVisibility')}
{enableSorting
? __('Table.columnsSorting')
: __('Table.columnsVisibility')}
</span>
<a
data-tooltip={__('Dialog.close')}
Expand Down
Loading