Skip to content

Commit

Permalink
fix(table): fix table setting error #162
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 4, 2021
1 parent a7a8b89 commit a2c89d2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/components/Table/src/BasicTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@
});
const { getLoading, setLoading } = useLoading(getProps);
const { getPaginationInfo, getPagination, setPagination } = usePagination(getProps);
const {
getPaginationInfo,
getPagination,
setPagination,
setShowPagination,
getShowPagination,
} = usePagination(getProps);
const {
getRowSelection,
Expand Down Expand Up @@ -229,6 +235,8 @@
getCacheColumns,
emit,
updateTableData,
setShowPagination,
getShowPagination,
getSize: () => {
return unref(getBindValues).size as SizeType;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,17 @@
cachePlainOptions.value = columns;
state.defaultCheckList = checkList;
} else {
const fixedColumns = columns.filter((item) =>
Reflect.has(item, 'fixed')
) as BasicColumn[];
// const fixedColumns = columns.filter((item) =>
// Reflect.has(item, 'fixed')
// ) as BasicColumn[];
unref(plainOptions).forEach((item: BasicColumn) => {
const findItem = fixedColumns.find((fCol) => fCol.dataIndex === item.dataIndex);
const findItem = columns.find((col: BasicColumn) => col.dataIndex === item.dataIndex);
if (findItem) {
item.fixed = findItem.fixed;
}
});
}
state.checkedList = checkList;
}
Expand Down
16 changes: 14 additions & 2 deletions src/components/Table/src/hooks/usePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ function itemRender({ page, type, originalElement }: ItemRender) {
export function usePagination(refProps: ComputedRef<BasicTableProps>) {
const configRef = ref<PaginationProps>({});

const show = ref(true);

const { t } = useI18n();
const getPaginationInfo = computed((): PaginationProps | boolean => {
const { pagination } = unref(refProps);

if (isBoolean(pagination) && !pagination) {
if (!unref(show) || (isBoolean(pagination) && !pagination)) {
return false;
}

return {
current: 1,
pageSize: PAGE_SIZE,
Expand All @@ -60,5 +63,14 @@ export function usePagination(refProps: ComputedRef<BasicTableProps>) {
function getPagination() {
return unref(getPaginationInfo);
}
return { getPagination, getPaginationInfo, setPagination };

function getShowPagination() {
return unref(show);
}

async function setShowPagination(flag: boolean) {
show.value = flag;
}

return { getPagination, getPaginationInfo, setShowPagination, getShowPagination, setPagination };
}
6 changes: 6 additions & 0 deletions src/components/Table/src/hooks/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export function useTable(
getForm: () => {
return unref(formRef) as FormActionType;
},
setShowPagination: async (show: boolean) => {
getTableInstance().setShowPagination(show);
},
getShowPagination: () => {
return getTableInstance().getShowPagination();
},
};

return [register, methods];
Expand Down
2 changes: 2 additions & 0 deletions src/components/Table/src/types/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export interface TableActionType {
getCacheColumns: () => BasicColumn[];
emit?: EmitType;
updateTableData: (index: number, key: string, value: any) => Recordable;
setShowPagination: (show: boolean) => Promise<void>;
getShowPagination: () => boolean;
}

export interface FetchSetting {
Expand Down

0 comments on commit a2c89d2

Please sign in to comment.