Browse Source
feat(table component): add 'expandRows' table action (#1537)
* fix(table component): add 'expandRows'
* feat(table component): add 'expandRows' table action
pull/1552/head
George Tan
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
18 additions and
2 deletions
-
src/components/Table/src/BasicTable.vue
-
src/components/Table/src/hooks/useTable.ts
-
src/components/Table/src/hooks/useTableExpand.ts
-
src/components/Table/src/types/table.ts
|
|
|
@ -199,7 +199,11 @@ |
|
|
|
|
|
|
|
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 = { |
|
|
|
onColumnsChange: (data: ColumnChangeParam[]) => { |
|
|
|
@ -300,6 +304,7 @@ |
|
|
|
getShowPagination, |
|
|
|
setCacheColumnsByField, |
|
|
|
expandAll, |
|
|
|
expandRows, |
|
|
|
collapseAll, |
|
|
|
scrollTo, |
|
|
|
getSize: () => { |
|
|
|
|
|
|
|
@ -152,6 +152,9 @@ export function useTable(tableProps?: Props): [ |
|
|
|
expandAll: () => { |
|
|
|
getTableInstance().expandAll(); |
|
|
|
}, |
|
|
|
expandRows: (keys: string[]) => { |
|
|
|
getTableInstance().expandRows(keys); |
|
|
|
}, |
|
|
|
collapseAll: () => { |
|
|
|
getTableInstance().collapseAll(); |
|
|
|
}, |
|
|
|
|
|
|
|
@ -37,6 +37,13 @@ export function useTableExpand( |
|
|
|
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[]) { |
|
|
|
const keys: string[] = []; |
|
|
|
const { childrenColumnName } = unref(propsRef); |
|
|
|
@ -54,5 +61,5 @@ export function useTableExpand( |
|
|
|
expandedRowKeys.value = []; |
|
|
|
} |
|
|
|
|
|
|
|
return { getExpandOption, expandAll, collapseAll }; |
|
|
|
return { getExpandOption, expandAll, expandRows, collapseAll }; |
|
|
|
} |
|
|
|
|
|
|
|
@ -87,6 +87,7 @@ export interface TableActionType { |
|
|
|
getSelectRows: <T = Recordable>() => T[]; |
|
|
|
clearSelectedRowKeys: () => void; |
|
|
|
expandAll: () => void; |
|
|
|
expandRows: (keys: string[]) => void; |
|
|
|
collapseAll: () => void; |
|
|
|
scrollTo: (pos: string) => void; // pos: id | "top" | "bottom"
|
|
|
|
getSelectRowKeys: () => string[]; |
|
|
|
|