From 435de17919306f1af173d0f01fb6361d52d7600e Mon Sep 17 00:00:00 2001 From: proxyteng Date: Tue, 19 Dec 2023 14:23:53 +0100 Subject: [PATCH] #4273 Add support for dataKey on TreeTable (#4936) --- api-generator/components/treetable.js | 6 +++ components/lib/treetable/BaseTreeTable.vue | 4 ++ components/lib/treetable/TreeTable.d.ts | 5 ++ components/lib/treetable/TreeTable.vue | 23 ++++++---- components/lib/treetable/TreeTableRow.vue | 46 +++++++++++-------- .../selection/CheckboxRowSelectionDoc.vue | 4 +- 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/api-generator/components/treetable.js b/api-generator/components/treetable.js index fc000a320..80cf64b7b 100644 --- a/api-generator/components/treetable.js +++ b/api-generator/components/treetable.js @@ -5,6 +5,12 @@ const TreeTableProps = [ default: 'null', description: 'An array of treenodes.' }, + { + name: 'dataKey', + type: 'string|function', + default: 'null', + description: 'Name of the field that uniquely identifies the a record in the data.' + }, { name: 'expandedKeys', type: 'array', diff --git a/components/lib/treetable/BaseTreeTable.vue b/components/lib/treetable/BaseTreeTable.vue index 0dcfb80d8..a34dbbdba 100644 --- a/components/lib/treetable/BaseTreeTable.vue +++ b/components/lib/treetable/BaseTreeTable.vue @@ -10,6 +10,10 @@ export default { type: null, default: null }, + dataKey: { + type: [String, Function], + default: 'key' + }, expandedKeys: { type: null, default: null diff --git a/components/lib/treetable/TreeTable.d.ts b/components/lib/treetable/TreeTable.d.ts index cfb06c3bd..2a0ea55ae 100755 --- a/components/lib/treetable/TreeTable.d.ts +++ b/components/lib/treetable/TreeTable.d.ts @@ -395,6 +395,11 @@ export interface TreeTableProps { * An array of treenodes. */ value?: TreeNode[] | undefined; + /** + * Name of the field that uniquely identifies the a record in the data. + * @defaultValue "key" + */ + dataKey?: string | ((item: any) => string) | undefined; /** * A map of keys to represent the state of the tree expansion state in controlled mode. * @see TreeTableExpandedKeys diff --git a/components/lib/treetable/TreeTable.vue b/components/lib/treetable/TreeTable.vue index 76b68b014..f138f87c2 100755 --- a/components/lib/treetable/TreeTable.vue +++ b/components/lib/treetable/TreeTable.vue @@ -83,7 +83,8 @@