We add two buttons to sort
the table in ascending or descending order; the user may select a column
and then press one of the buttons. In addition, we add variables to the
column headers that we can fill with a symbol (special Unicode
character) to indicate the ordering:
// Sort table and display sort indicators
Parameter MODE // ASC or DES
// reset sort indicators
Clear V[mat.stat.sortsymbol_*]
// determine selected column
Clear V[current_column]
if V[mat.stat.columnselection.matnr]
Set V[current_column] "matnr"
endif
if V[mat.stat.columnselection.amount]
Set V[current_column] "amount"
endif
if V[mat.stat.columnselection.unit]
Set V[current_column] "unit"
endif
// no column selected? then take first one (material number)
if not V[current_column]
Set V[current_column] "matnr"
endif
// set sort indicator symbol and sort table by selected column
if U[MODE=ASC]
Set V[mat.stat.sortsymbol_&V[current_column]] "▲"
Sort table="mat" orderBy="&V[current_column]"
else
Set V[mat.stat.sortsymbol_&V[current_column]] "▼"
Sort table="mat" orderBy="&V[current_column]" -descending
endif
// Reset column selection
Clear V[mat.stat.columnselection.*]
// Return with success message
Return "S: Table sorted" -statusline