Purpose Display a sort indicator in a table column header We implement the possibility to sort a table by a column, indicating the sorting by a symbol in the column header. |
Solution We start with the following table: Table (3,6) (10,40) name="mat" rows="12" fixedColumns=3Column "Material" size=10 name="matnr" Column "Amount" size=10 name="amount" Column "Unit" size=10 name="unit" 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: / / table with column selection and sort indicator variablesTable (3,6) (10,40) name="mat" rows="10" -singleColumnSelection fixedColumns=3 Column "Material &V[mat.stat.sortsymbol_matnr]" size=10 name="matnr" Column "Amount &V[mat.stat.sortsymbol_amount]" size=10 name="amount" Column "Unit &V[mat.stat.sortsymbol_unit]" size=10 name="unit" // buttons to sort the table Pushbutton (4,46) "@3E\QSort ascending@" size=(1,2) process="sort_table.txt" using MODE = "ASC" Pushbutton (4,52) "@3F\QSort descending@" size=(1,2) process="sort_table.txt" using MODE = "DES" InputScript "sort_table.txt": // Sort table and display sort indicators // reset sort indicators // determine selected 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 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 // Return with success
message |
Components |