Global augmentation of sort

Tags: #<Tag:0x00007f8b1d9caea0> #<Tag:0x00007f8b1d9cad38>

Is there an easy way to globally augment the sort behavior while preserving the default sorting methods?

I know that I can set compareFunctionFactory but this seems to completely override any default sorting behavior. I essentially want to pre-process the sorted values, but preserve the built-in text/numeric/date sorting afterwards, ie if the pre-sort returns 0, use the built-in sort.

It seems the built-in sorting methods are not exposed so I cannot call through to them.

Hi @abeall

I’m afraid that, besides compareFunctionFactory custom function, we don’t have any straightforward solution for a global augmentation of sorting plugin.

The one thing that seems to be helpful from the description of your use case might be this method: https://handsontable.com/docs/javascript-data-grid/api/column-sorting/#setsortconfig

Thanks for the response.

I realized actually that what I wanted wouldn’t quite help with my case, because the sort function does not have a row context (only values to compare). What I actually am trying to do is to keep certain rows from sorting. I want to use HT’s sort logic for all rows except the first row. Is there a way to do this? It seems being able to exclude frozen or fixed rows would be pretty useful.

The one thing that seems to be helpful from the description of your use case might be this method:
https://handsontable.com/docs/javascript-data-grid/api/column-sorting/#setsortconfig

Thanks, that’s actually exactly what I’m doing currently. Unfortunately it requires me to apply sorting logic to all the column types, which has turned out a bit more complicated than it looks. :slight_smile: I’d love to use HT’s out of the box sorting logic, because it works great for all sorts of data types (dates, numbers, etc) and just not sort the first row.

Hi @abeall

I think I have an example of what you exactly need here: https://jsfiddle.net/aszymanski/h1u0gxeL/

This solution allows you to ignore the rows that you don’t want to sort.

Indeed that’s exactly what I was trying to do! Thanks!

You know what I’m going to ask next… would you consider a feature enhancement PR that basically enables this behavior out of the box? I know feature bloat is always a concern but it seems like a pretty clear improvement to allow fixed rows to be excluded from sort and filter. Or maybe this workaround could be documented, I don’t think filtersRowsMap is documented?

That would be more than appreciated! However, I need to discuss it first with our PM to see if we would be able to implement it in acceptable time span. I’ll get back to you once I have more info on that.

1 Like