You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Datagrid] Make it possible to accept custom sorter for EuiDataGrid column #6867
Is your feature request related to a problem? Please describe.
It would be nice to be able to extend the sorting behaviour of EuiDataGrid for specific types with a custom sorter.
An example of this would be the ip sorting: not just a text comparison, rather providing a sorter which supports both IPv4 and IPv6 would be nice.
Another example would be a sorter for a version field.
Describe the solution you'd like
An additional property for the sorting like customSorters: { [columnIdA]: (a, b) => ..., [columnIdB]: (a, b) => ... }
Describe alternatives you've considered
Sorting the data before submitting to the Eui DataGrid, but this will completely disable all inMemory enhancements.
constcolumns=[{id: 'columnWithCustomSchema',schema: 'schemaWithCustomSorting',},];constschemaDetectors=[{type: 'schemaWithCustomSorting',comparator: (a,b,direction: 'asc'|'desc')=>{// ... write your sort function here - see the above EUI demo link},sortTextAsc: 'Sort ascending',sortTextDesc: 'Sort descending',},];<EuiDataGridcolumns={columns}schemaDetectors={schemaDetectors}// ... other required props/>
👋 This issue hasn't seen activity in 3 days, so we're automatically closing this issue as answered. Please leave a comment if that's not the case, or if you have any remaining questions or issues.
I had a go using that, but the big problem is the string type for the comparable values which is very limiting: for some entries I need to access the raw object in order to perform required transformations to compare.
Or at least provide the index for both entries, so that we can access the raw objects from the table itself.
that feels like it'd be a pretty quick/easy change since it's an enhancement and not a breaking change. would you be interested in contributing that to EUI? 👀 (no worries if not, totally not trying to peer pressure you! - if you'd rather have EUI pick up this work, that's totally valid)
Activity
tkajtoch commentedon Jun 22, 2023
Hi Marco! We'll look into that, triage the work needed and get back to you shortly
cee-chen commentedon Jun 22, 2023
Custom sorting is supported via the
schemaDetectorsprop. Take a look at the demo JS for the first example on this page:https://elastic.github.io/eui/#/tabular-content/data-grid-schema-columns#schemas
The basic necessary logic is:
github-actions commentedon Jun 26, 2023
👋 This issue hasn't seen activity in 3 days, so we're automatically closing this issue as answered. Please leave a comment if that's not the case, or if you have any remaining questions or issues.
dej611 commentedon Dec 7, 2023
I had a go using that, but the big problem is the
stringtype for the comparable values which is very limiting: for some entries I need to access the raw object in order to perform required transformations to compare.Or at least provide the index for both entries, so that we can access the raw objects from the table itself.
cee-chen commentedon Dec 7, 2023
Ahh gotcha. We could likely add a 4th param to the
comparatorcallback with the full set of values here:eui/src/components/datagrid/utils/sorting.ts
Line 83 in 976e603
that feels like it'd be a pretty quick/easy change since it's an enhancement and not a breaking change. would you be interested in contributing that to EUI? 👀 (no worries if not, totally not trying to peer pressure you! - if you'd rather have EUI pick up this work, that's totally valid)
dej611 commentedon Dec 7, 2023
I think I can have a go with that.
Edit => #7406