-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow consumers to customize the sorting logic of the Table components #425
Comments
Not sure... eg. I think it doesn't make sense to let the user sort on a column named "first name" and the actual sort will be done on some other property. The I think it makes sense to have a For basic table, the sort needs to work both on ES and the browser. So putting custom js logic there makes little sense. With the new |
I think this was a poorly chosen example. A real example from index management is sorting a field whose value is size in bytes scaled to correct unit (10kb, 100mb, 9tb, etc). so we want to sort on actual byte value, which I calculate and then sort on that value. Another example: API returns strings a lot of times when the value is numeric. So, forcing numeric value on the string before sorting avoids all the dumb bugs with textual sort of numeric values. |
few comments:
do you mean that you get the value from ES already "rounded" as strings (e.g "10kb", "9tb")? This should only be the retuned when
If a value is supposed to be numeric, the API should return a number, not a string and if that's not the case, I'd suggest consulting the ES team about it to understand why it's like that (maybe there's a reason, maybe it's a bug). In any case, in an ideal world we wouldn't need to this change for the described scenarios - but we're not leaving in an ideal world, and even if these described behaviours of ES will be fixed (if they need to be fixed) in the future, we still need to support older APIs. One option is to translate/fix the data as it's being fetched before it's passed down to the table. Would that work? If we want to go ahead and this support in the table, then I'd say this needs to only go in the Introduce a sort value callback per column - I'd incorporate this with the existing columns={[
{
sortable: {
value: (item) => fetch the sort value from the item
}
}
]} This means that you'll start creating "gaps" between basic table and in-memory table... some properties that should be common between the two will be supported by one and not by the other... I'm not a big fan of that (the Another option that we can consider is to introduce the <EuiInMemoryTable
...
sorting={{
sortValue: (field, item, value = undefined) => {
switch(field) {
case 'count':
return Number(item.stringThatLooksLikeANumber)
default:
return value;
}
}
}}
/> this one is a big more "verbose" but doesn't clutter the columns configuration but centralized this functionality in one place for all the columns (now you have column specific logic in 2 places). Not a big fan of either way... so if we could just prep the data better before we pass it to the table, that'd be great... if we really can't, I think I'd prefer the first option (enabling defining |
👍 I am currently converting the table of anomalies in the ML UI to EUI / React and there are three columns where I could do with this functionality.
Of the two options described above, my preference would be for the first option, allowing a |
Per discussion with @bmcconaghy, we may want to customize the way the columns of a table sort the rows within that table. For example, if that row contains JSON maybe we can sort based on a specific field within the JSON.
One possible solution would be to add a
getSortValue
property to thecolumns
Table prop. The consumer can define a function which accepts the cell and row as arguments, and returns a value with which the Table can perform sort comparisons.The text was updated successfully, but these errors were encountered: