From 861fde2c03f0b35f2b6a6748e8de47620b588281 Mon Sep 17 00:00:00 2001 From: Marco Liberati Date: Thu, 7 Dec 2023 17:20:31 +0100 Subject: [PATCH] :sparkles: Add new argument for advanced use cases --- src/components/datagrid/data_grid_types.ts | 4 ++-- src/components/datagrid/utils/sorting.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/datagrid/data_grid_types.ts b/src/components/datagrid/data_grid_types.ts index 3d17c777638..b5fc283f446 100644 --- a/src/components/datagrid/data_grid_types.ts +++ b/src/components/datagrid/data_grid_types.ts @@ -85,9 +85,9 @@ export interface EuiDataGridSchemaDetector { */ detector: (value: string) => number; /** - * A custom comparator function when performing in-memory sorting on this data type, takes `(a: string, b: string, direction: 'asc' | 'desc) => -1 | 0 | 1` + * A custom comparator function when performing in-memory sorting on this data type, takes `(a: string, b: string, direction: 'asc' | 'desc', indexes: {aIndex: number, bIndex: number}) => -1 | 0 | 1` */ - comparator?: (a: string, b: string, direction: 'asc' | 'desc') => -1 | 0 | 1; + comparator?: (a: string, b: string, direction: 'asc' | 'desc', indexes: {aIndex: number, bIndex: number}) => -1 | 0 | 1; /** * The icon used to visually represent this data type. Accepts any `EuiIcon IconType`. */ diff --git a/src/components/datagrid/utils/sorting.ts b/src/components/datagrid/utils/sorting.ts index c697b30045c..651eda12d55 100644 --- a/src/components/datagrid/utils/sorting.ts +++ b/src/components/datagrid/utils/sorting.ts @@ -80,7 +80,7 @@ export const useSorting = ({ } } - const result = comparator(aValue, bValue, column.direction); + const result = comparator(aValue, bValue, column.direction, {aIndex: a.index, bIndex: b.index}); // only return if the columns are unequal, otherwise allow the next sort-by column to run if (result !== 0) return result; }