Unverified 提交 1dc6faf3 作者: George Tan 提交者: GitHub

feat(table component): add 'expandRows' table action (#1537)

* fix(table component): add 'expandRows'

* feat(table component): add 'expandRows' table action
上级 598ce5a1
...@@ -199,7 +199,11 @@ ...@@ -199,7 +199,11 @@
const { getRowClassName } = useTableStyle(getProps, prefixCls); const { getRowClassName } = useTableStyle(getProps, prefixCls);
const { getExpandOption, expandAll, collapseAll } = useTableExpand(getProps, tableData, emit); const { getExpandOption, expandAll, expandRows, collapseAll } = useTableExpand(
getProps,
tableData,
emit,
);
const handlers: InnerHandlers = { const handlers: InnerHandlers = {
onColumnsChange: (data: ColumnChangeParam[]) => { onColumnsChange: (data: ColumnChangeParam[]) => {
...@@ -300,6 +304,7 @@ ...@@ -300,6 +304,7 @@
getShowPagination, getShowPagination,
setCacheColumnsByField, setCacheColumnsByField,
expandAll, expandAll,
expandRows,
collapseAll, collapseAll,
scrollTo, scrollTo,
getSize: () => { getSize: () => {
......
...@@ -152,6 +152,9 @@ export function useTable(tableProps?: Props): [ ...@@ -152,6 +152,9 @@ export function useTable(tableProps?: Props): [
expandAll: () => { expandAll: () => {
getTableInstance().expandAll(); getTableInstance().expandAll();
}, },
expandRows: (keys: string[]) => {
getTableInstance().expandRows(keys);
},
collapseAll: () => { collapseAll: () => {
getTableInstance().collapseAll(); getTableInstance().collapseAll();
}, },
......
...@@ -37,6 +37,13 @@ export function useTableExpand( ...@@ -37,6 +37,13 @@ export function useTableExpand(
expandedRowKeys.value = keys; expandedRowKeys.value = keys;
} }
function expandRows(keys: string[]) {
// use row ID expands the specified table row
const { isTreeTable } = unref(propsRef);
if (!isTreeTable) return;
expandedRowKeys.value = [...expandedRowKeys.value, ...keys];
}
function getAllKeys(data?: Recordable[]) { function getAllKeys(data?: Recordable[]) {
const keys: string[] = []; const keys: string[] = [];
const { childrenColumnName } = unref(propsRef); const { childrenColumnName } = unref(propsRef);
...@@ -54,5 +61,5 @@ export function useTableExpand( ...@@ -54,5 +61,5 @@ export function useTableExpand(
expandedRowKeys.value = []; expandedRowKeys.value = [];
} }
return { getExpandOption, expandAll, collapseAll }; return { getExpandOption, expandAll, expandRows, collapseAll };
} }
...@@ -87,6 +87,7 @@ export interface TableActionType { ...@@ -87,6 +87,7 @@ export interface TableActionType {
getSelectRows: <T = Recordable>() => T[]; getSelectRows: <T = Recordable>() => T[];
clearSelectedRowKeys: () => void; clearSelectedRowKeys: () => void;
expandAll: () => void; expandAll: () => void;
expandRows: (keys: string[]) => void;
collapseAll: () => void; collapseAll: () => void;
scrollTo: (pos: string) => void; // pos: id | "top" | "bottom" scrollTo: (pos: string) => void; // pos: id | "top" | "bottom"
getSelectRowKeys: () => string[]; getSelectRowKeys: () => string[];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论