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): fullRow render and sort logic #1080

Merged
merged 1 commit into from
Jun 27, 2022
Merged
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
7 changes: 5 additions & 2 deletions src/table/hooks/useDragSort.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// 表格 行拖拽 + 列拖拽功能
import { SetupContext, computed, toRefs, ref, watch, h } from 'vue';
import Sortable, { SortableEvent, SortableOptions } from 'sortablejs';
import Sortable, { SortableEvent, SortableOptions, MoveEvent } from 'sortablejs';
import get from 'lodash/get';
import isFunction from 'lodash/isFunction';
import { TableRowData, TdPrimaryTableProps, DragSortContext } from '../type';
import useClassName from './useClassName';
import log from '../../_common/js/log';
import { hasClass } from '../../utils/dom';
import swapDragArrayElement from '../../_common/js/utils/swapDragArrayElement';
import { BaseTableColumns } from '../interface';

Expand All @@ -19,7 +20,7 @@ import { BaseTableColumns } from '../interface';
*/
export default function useDragSort(props: TdPrimaryTableProps, context: SetupContext) {
const { sortOnRowDraggable, dragSort, data, rowKey } = toRefs(props);
const { tableDraggableClasses, tableBaseClass } = useClassName();
const { tableDraggableClasses, tableBaseClass, tableFullRowClasses } = useClassName();
const primaryTableRef = ref(null);
const columns = ref<BaseTableColumns>(props.columns || []);
// @ts-ignore 判断是否有拖拽列
Expand Down Expand Up @@ -71,6 +72,8 @@ export default function useDragSort(props: TdPrimaryTableProps, context: SetupCo
ghostClass: tableDraggableClasses.ghost,
chosenClass: tableDraggableClasses.chosen,
dragClass: tableDraggableClasses.dragging,
filter: `.${tableFullRowClasses.base}`, // 过滤首行尾行固定
onMove: (evt: MoveEvent) => !hasClass(evt.related, tableFullRowClasses.base),
onEnd(evt: SortableEvent) {
// 处理受控:拖拽列表恢复原始排序
dragInstanceTmp?.sort(lastRowList.value);
Expand Down
2 changes: 1 addition & 1 deletion src/table/tbody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default defineComponent({
});

const list = [getFullRow(columnLength, 'first-full-row'), ...trNodeList, getFullRow(columnLength, 'last-full-row')];
const isEmpty = !this.data?.length && !this.loading;
const isEmpty = !this.data?.length && !this.loading && !this.firstFullRow && !this.lastFullRow;

const translate = `translate(0, ${this.translateY}px)`;
const posStyle = {
Expand Down