From 8e632d93ac5629053da128e74c39e39b22a5a5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Tue, 31 May 2022 15:03:53 +0300 Subject: [PATCH] Fixed #2589 - DataTable: support passing a function to the dataKey prop --- api-generator/components/datatable.js | 2 +- src/components/datatable/DataTable.d.ts | 5 ++++- src/components/datatable/DataTable.vue | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api-generator/components/datatable.js b/api-generator/components/datatable.js index 9cf87e0af..5108bc7c5 100644 --- a/api-generator/components/datatable.js +++ b/api-generator/components/datatable.js @@ -7,7 +7,7 @@ const DataTableProps = [ }, { name: "dataKey", - type: "string", + type: "string|function", default: "null", description: "Name of the field that uniquely identifies the a record in the data." }, diff --git a/src/components/datatable/DataTable.d.ts b/src/components/datatable/DataTable.d.ts index e44ec581e..36f291ce7 100755 --- a/src/components/datatable/DataTable.d.ts +++ b/src/components/datatable/DataTable.d.ts @@ -7,6 +7,8 @@ type DataTablePaginatorPositionType = 'top' | 'bottom' | 'both' | undefined; type DataTableSortFieldType = string | ((item: any) => string) | undefined; +type DataTableDataKeyType = string | (() => string) | undefined; + type DataTableMultiSortMetaType = DataTableSortMeta[] | undefined | null; type DataTableSortOrderType = 1 | 0 | -1 | undefined | null; @@ -465,8 +467,9 @@ export interface DataTableProps { value?: any[] | undefined; /** * Name of the field that uniquely identifies the a record in the data. + * @see DataTableDataKeyType */ - dataKey?: string | undefined; + dataKey?: DataTableDataKeyType; /** * Number of rows to display per page. */ diff --git a/src/components/datatable/DataTable.vue b/src/components/datatable/DataTable.vue index abb7f78ad..5d1371a4d 100755 --- a/src/components/datatable/DataTable.vue +++ b/src/components/datatable/DataTable.vue @@ -93,7 +93,7 @@ export default { default: null }, dataKey: { - type: String, + type: [String, Function], default: null }, rows: {