sematable icon indicating copy to clipboard operation
sematable copied to clipboard

can 'sortKey' be a function?

Open pgoldweic opened this issue 6 years ago • 3 comments

I'm wondering if I can pass a function as the value of 'sortKey' when defining my headers object. In my use case, I need to sort one of the columns based on a value calculated from a couple of fields in each of the objects. Having 'sortKey' as a function would allow me to not have to redundantly define a property for my data that is calculated based on the value of other existent properties.

pgoldweic avatar Feb 20 '18 18:02 pgoldweic

Well, I just noticed in the code that the 'sortKey' prop is actually expected to be a string :-(. However, it would be a nice feature to add support for.

pgoldweic avatar Feb 20 '18 18:02 pgoldweic

Yeah, this is not currently possible, but I think you're thinking of something more like a sortValue function if I understand correctly. There are other similar cases where computed data can be used instead of properties but I'm not sure we should handle that in sematable. I'll think about this some more.

If you want to avoid computing these properties "manually" whenever data changes, you can consider using Javascript getters (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get).

amir-hadzic avatar Feb 20 '18 19:02 amir-hadzic

That sounds like an interesting idea, and certainly worth for me to look into it. Thanks for mentioning it.

pgoldweic avatar Feb 20 '18 20:02 pgoldweic