[GH #1975] Sorting issue with HandsonTable when using the compareFunctionFactory function

Tags: #<Tag:0x00007efc6140f100> #<Tag:0x00007efc6140efc0>

Implementing the compareFunctionFactory function has some issue, and there is no way to revert to the original data order after sorting in ascending and descending order using compareFunctionFactory. The ‘compareFunctionFactory’ is particularly concerning due to its inability to revert to the original data order and its failure to trigger after sorting orders. However, without using the compareFunctionFactory, the data return to its original order after sorting in both ascending and descending orders.

JsFiddle Demo
https://jsfiddle.net/rmotukuri2025/o8mpherv/1

HandsonTable on table settings

hot = new Handsontable(container, {
data: gridData,
startRows: 8,
startCols: 8,
headerTooltips: {
rows: false,
columns: true,
},
// sortIndicator: true,
multiColumnSorting: {
sortEmptyCells: false,
indicator: true,
headerAction: true,
compareFunctionFactory: compareFunctionFactory,
//sortColumnIndexes: getSortableColumnsIndexes([‘Name’, ‘Code’])
}
}

Hi @ramanjaneyareddy.mot

Thank you for contacting us. I checked the example, but it throws an error when I try to sort the data. It seems that it was missing function return statement, but the fact that it’s not returning to the original order is most likely caused byt the logic itself inside this function. Here’s your version without the error: https://jsfiddle.net/handsoncode/evjgh6rL/

I checked on the other examples and the function works correctly: https://jsfiddle.net/handsoncode/r4s3Lnoy/

@adrian.szymanski, Sorting is not working with formula columns. Could you try with this scenario using compareFunctionFactory?.

Hi @ramanjaneyareddy.mot

I checked our formula example with compareFunctionFactory from our documentation and it works correctly: https://jsfiddle.net/handsoncode/ch38r9yk/

If it doesn’t work with your custom function there must be some issue within the logic of this function so I would recommend to check if there aren’t any conflicts there.

Hi @ adrian.szymanski,

Could you please check this demo where formula columns are causing sorting issues? Additionally, script errors from the Handsontable libraries occurred during sorting of the formula columns.

Demo:

FormulaeColumnsIssue - JSFiddle - Code Playground

ScriptErrors:

  1. There is no AST with such key in the cache at Le.fetchCachedResult (handsontable.full.min.js:86:3773)

  2. Value of the formula cell is not computed.at $t.getCellValue (handsontable.full.min.js:151:2749)

  3. Uncaught TypeError: Cannot read properties of null (reading ‘startColumn’).at get startColumnVisible (handsontable.full.min.js:929:69006)

Hi @ramanjaneyareddy.mot

I checked the example and while minifying it I discovered that the source of the issue the formula you use in the last column starting from the second row:

Can you please review it? I’m not able to get the same error with any other formulas I tested.

Hi @adrian.szymanski,

Please check the updated JSFiddle demo with the correct formulas. Let me know if you need more details.

FormulaeColumnsIssue - JSFiddle - Code Playground

Hi @ramanjaneyareddy.mot

There’s still some issues with the formulas, but we did further investigation with my colleague and managed to fix them: https://jsfiddle.net/handsoncode/8ga2cLx3/

However, there’s another issue, and that’s an internal bug caused by the fact that after performing sorting operation our plugin change the ranges but the HyperFormula isn’t properly informed about those changes. I will add your case to the issue and will update you once we have the fix ready.

Hi @adrian.szymanski

Do you have any updates on this issue? I look forward to hearing from you.

Hi @ramanjaneyareddy.mot

Not yet, it’s more complicated issue, and it has to be determined how to handle this behavior. It’s added to our backlog and I will let you know as soon as I have any updates.