Question
Please advise on how to correctly write a script for sorting a table using a button.
=: listSort(list: $selectlist; type: "number"; direction: "desc")
selectlist: selectList(table: $#ntn; field: 'quantity')
I press the button and the sorting does not occur. Sorting is needed in both simple and temporary tables.
Answer
Good afternoon! This code will not work. It does not affect the table as it only retrieves and sorts.
If you need the sorting to occur specifically when a button is pressed, you can use a process variable ā which lives during the transaction.
In this case, in the button action code, we set a variable that records a signal indicating that we need to sort:
=: procVar(name: "order"; value: true)
In the table formatting code, we write:
f1=: if(condition: $@order = true; then: $order)
order: setRowsOrder(ids: $sorted_ids)
sorted_ids: selectList(table: $#ntn; field: 'id'; order: 'quantity' desc)
This approach is not designed for a table with millions of rows where automatic pagination is enabled. In this case, it is better to use a sorting column in the table settings and reload the table using linkToTable.