From 7fdac4510f0c0477c24c8fb494ed358d8391310e Mon Sep 17 00:00:00 2001 From: Ashik Meerankutty Date: Sun, 1 Mar 2020 08:21:59 +0530 Subject: [PATCH] Added isSortable to Datagrid columns (#2952) * Added isSorting to data_grid_types * do not display column in filter if isSortable is false * added isSorted = false in docs * update in changelog * Added isSortable flag to EuiDataGridSchemaDetector * Fixed empty sortable columns popover * Removed unwanted return * Fixes in empty sortable popover * Added isSortable in data grid test --- CHANGELOG.md | 1 + src-docs/src/views/datagrid/datagrid.js | 1 + src/components/datagrid/column_sorting.tsx | 12 +++++++++--- src/components/datagrid/data_grid.test.tsx | 1 + src/components/datagrid/data_grid_schema.tsx | 9 +++++++++ src/components/datagrid/data_grid_types.ts | 4 ++++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e70017473dd..30caf76152a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) +- Added `isSortable` props to `EuiDataGridColumn` and `EuiDataGridSchemaDetector` to mark them as un-sortable ([#2952](https://github.com/elastic/eui/pull/2952)) - Converted `EuiForm` to TypeScript, added many missing `/form` Prop types ([#2896](https://github.com/elastic/eui/pull/2896)) - Empty table th elements replaced with td in `EuiTable`. ([#2934](https://github.com/elastic/eui/pull/2934)) - Added default prompt text to `aria-describedby` for `EuiFilePicker` ([#2919](https://github.com/elastic/eui/pull/2919)) diff --git a/src-docs/src/views/datagrid/datagrid.js b/src-docs/src/views/datagrid/datagrid.js index 67a438cc830..62864d99fce 100644 --- a/src-docs/src/views/datagrid/datagrid.js +++ b/src-docs/src/views/datagrid/datagrid.js @@ -55,6 +55,7 @@ const columns = [ }, { id: 'phone', + isSortable: false, }, { id: 'version', diff --git a/src/components/datagrid/column_sorting.tsx b/src/components/datagrid/column_sorting.tsx index d38536088b6..8f9724194c6 100644 --- a/src/components/datagrid/column_sorting.tsx +++ b/src/components/datagrid/column_sorting.tsx @@ -96,6 +96,12 @@ export const useColumnSorting = ( const numberOfSortedFields = sorting.columns.length; + const inactiveSortableColumns = inactiveColumns.filter(({ id, isSortable }) => + schema.hasOwnProperty(id) && schema[id].columnType != null + ? getDetailsForSchema(schemaDetectors, schema[id].columnType).isSortable + : isSortable !== false + ); + const columnSorting = ( )} - {(inactiveColumns.length > 0 || sorting.columns.length > 0) && ( + {(inactiveSortableColumns.length > 0 || sorting.columns.length > 0) && ( - {inactiveColumns.length > 0 && ( + {inactiveSortableColumns.length > 0 && ( - {inactiveColumns.map(({ id }) => ( + {inactiveSortableColumns.map(({ id }) => (