feat(treeTable): add function collapseRows and demo (#3375)
* feat(treeTable): add function collapseRows and demo
This commit is contained in:
parent
943f50051c
commit
e656b5d8dc
|
|
@ -207,7 +207,7 @@
|
||||||
|
|
||||||
const { getRowClassName } = useTableStyle(getProps, prefixCls);
|
const { getRowClassName } = useTableStyle(getProps, prefixCls);
|
||||||
|
|
||||||
const { getExpandOption, expandAll, expandRows, collapseAll } = useTableExpand(
|
const { getExpandOption, expandAll, expandRows, collapseRows, collapseAll } = useTableExpand(
|
||||||
getProps,
|
getProps,
|
||||||
tableData,
|
tableData,
|
||||||
emit,
|
emit,
|
||||||
|
|
@ -308,8 +308,9 @@
|
||||||
getShowPagination,
|
getShowPagination,
|
||||||
setCacheColumnsByField,
|
setCacheColumnsByField,
|
||||||
expandAll,
|
expandAll,
|
||||||
expandRows,
|
|
||||||
collapseAll,
|
collapseAll,
|
||||||
|
expandRows,
|
||||||
|
collapseRows,
|
||||||
scrollTo,
|
scrollTo,
|
||||||
getSize: () => {
|
getSize: () => {
|
||||||
return unref(getBindValues).size as SizeType;
|
return unref(getBindValues).size as SizeType;
|
||||||
|
|
|
||||||
|
|
@ -156,11 +156,14 @@ export function useTable(tableProps?: Props): [
|
||||||
expandAll: () => {
|
expandAll: () => {
|
||||||
getTableInstance().expandAll();
|
getTableInstance().expandAll();
|
||||||
},
|
},
|
||||||
|
collapseAll: () => {
|
||||||
|
getTableInstance().collapseAll();
|
||||||
|
},
|
||||||
expandRows: (keys: Key[]) => {
|
expandRows: (keys: Key[]) => {
|
||||||
getTableInstance().expandRows(keys);
|
getTableInstance().expandRows(keys);
|
||||||
},
|
},
|
||||||
collapseAll: () => {
|
collapseRows: (keys: Key[]) => {
|
||||||
getTableInstance().collapseAll();
|
getTableInstance().collapseRows(keys);
|
||||||
},
|
},
|
||||||
scrollTo: (pos: string) => {
|
scrollTo: (pos: string) => {
|
||||||
getTableInstance().scrollTo(pos);
|
getTableInstance().scrollTo(pos);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ export function useTableExpand(
|
||||||
expandedRowKeys.value = keys;
|
expandedRowKeys.value = keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function collapseAll() {
|
||||||
|
expandedRowKeys.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
function expandRows(keys: (string | number)[]) {
|
function expandRows(keys: (string | number)[]) {
|
||||||
// use row ID expands the specified table row
|
// use row ID expands the specified table row
|
||||||
const { isTreeTable } = unref(propsRef);
|
const { isTreeTable } = unref(propsRef);
|
||||||
|
|
@ -44,6 +48,13 @@ export function useTableExpand(
|
||||||
expandedRowKeys.value = [...expandedRowKeys.value, ...keys];
|
expandedRowKeys.value = [...expandedRowKeys.value, ...keys];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function collapseRows(keys: (string | number)[]) {
|
||||||
|
// use row ID collapses the specified table row
|
||||||
|
const { isTreeTable } = unref(propsRef);
|
||||||
|
if (!isTreeTable) return;
|
||||||
|
expandedRowKeys.value = unref(expandedRowKeys).filter((key) => !keys.includes(key));
|
||||||
|
}
|
||||||
|
|
||||||
function getAllKeys(data?: Recordable[]) {
|
function getAllKeys(data?: Recordable[]) {
|
||||||
const keys: string[] = [];
|
const keys: string[] = [];
|
||||||
const { childrenColumnName } = unref(propsRef);
|
const { childrenColumnName } = unref(propsRef);
|
||||||
|
|
@ -57,9 +68,5 @@ export function useTableExpand(
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
function collapseAll() {
|
return { getExpandOption, expandAll, collapseAll, expandRows, collapseRows };
|
||||||
expandedRowKeys.value = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return { getExpandOption, expandAll, expandRows, collapseAll };
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,9 @@ export interface TableActionType {
|
||||||
getSelectRows: <T = Recordable>() => T[];
|
getSelectRows: <T = Recordable>() => T[];
|
||||||
clearSelectedRowKeys: () => void;
|
clearSelectedRowKeys: () => void;
|
||||||
expandAll: () => void;
|
expandAll: () => void;
|
||||||
expandRows: (keys: (string | number)[]) => void;
|
|
||||||
collapseAll: () => void;
|
collapseAll: () => void;
|
||||||
|
expandRows: (keys: (string | number)[]) => void;
|
||||||
|
collapseRows: (keys: (string | number)[]) => void;
|
||||||
scrollTo: (pos: string) => void; // pos: id | "top" | "bottom"
|
scrollTo: (pos: string) => void; // pos: id | "top" | "bottom"
|
||||||
getSelectRowKeys: () => Key[];
|
getSelectRowKeys: () => Key[];
|
||||||
deleteSelectRowByKey: (key: string) => void;
|
deleteSelectRowByKey: (key: string) => void;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
<template #toolbar>
|
<template #toolbar>
|
||||||
<a-button type="primary" @click="expandAll">展开全部</a-button>
|
<a-button type="primary" @click="expandAll">展开全部</a-button>
|
||||||
<a-button type="primary" @click="collapseAll">折叠全部</a-button>
|
<a-button type="primary" @click="collapseAll">折叠全部</a-button>
|
||||||
|
<a-button type="primary" @click="collapseRows(['4'])">折叠第五行</a-button>
|
||||||
|
<a-button type="primary" @click="expandRows(['4'])">展开第五行</a-button>
|
||||||
</template>
|
</template>
|
||||||
</BasicTable>
|
</BasicTable>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -12,7 +14,7 @@
|
||||||
import { BasicTable, useTable } from '@/components/Table';
|
import { BasicTable, useTable } from '@/components/Table';
|
||||||
import { getBasicColumns, getTreeTableData } from './tableData';
|
import { getBasicColumns, getTreeTableData } from './tableData';
|
||||||
|
|
||||||
const [register, { expandAll, collapseAll }] = useTable({
|
const [register, { expandAll, collapseAll, expandRows, collapseRows }] = useTable({
|
||||||
title: '树形表格',
|
title: '树形表格',
|
||||||
isTreeTable: true,
|
isTreeTable: true,
|
||||||
rowSelection: {
|
rowSelection: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue