Commands for Interactive Sorting by One or More Columns
For Tablelist Version 5.13
by
Csaba Nemethi
csaba.nemethi@t-online.deContents
Overview
The commands described in this reference page enable the user to sort the items of a tablelist widget based on one or more of its columns, with the aid of the left mouse button.
If the tablelist::sortByColumn
command was
specified as the value of the -labelcommand
configuration option, then by pressing mouse button 1 over one of
the header labels and later releasing it over the same label, the
items will be sorted based on the elements of the corresponding
column.
If the tablelist::addToSortColumns
command was specified as the value of the -labelcommand2
configuration option, then by pressing mouse button 1 together with
the Shift
key over one of the header labels and later
releasing it over the same label, the corresponding column will be
appended to the list of sort columns, or (if it was already
contained in that list) the corresponding sort order will be
toggled; in both cases, the items will be sorted based on the
updated lists of sort columns and sort orders.
The
tablelist::sortByColumn
Command
- NAME
tablelist::sortByColumn
– Sort the items of a tablelist widget based on one of its columns- SYNOPSIS
-
tablelist::sortByColumn pathName columnIndex
- DESCRIPTION
- This command sorts the items of the tablelist widget
pathName
based on the elements of the column specified bycolumnIndex
. This is done by invoking thesortbycolumn
subcommand of the Tcl command associated with the given tablelist widget. If the items were last sorted in increasing order, based on the same column given bycolumnIndex
, and no subsequent invocation of theresetsortinfo
subcommand was made, then the last argument passed tosortbycolumn
will be-decreasing
, otherwise-increasing
. - After sorting the items, the virtual event
<<TablelistColumnSorted>>
is generated. For Tk versions 8.5 or higher, this virtual event is generated with its-data
option set to a list consisting of the numerical column index and the sort order (decreasing
orincreasing
). The command returns the sort order, asdecreasing
orincreasing
. - If the specified column's
-showlinenumbers
option has been set to true, then the actions described above are not performed and the return value is an empty string. tablelist::sortByColumn
is usually specified as the value of the-labelcommand
configuration option for a tablelist widget.- KEYWORDS
- tablelist, sort, column, widget
The
tablelist::addToSortColumns
Command
- NAME
tablelist::addToSortColumns
– Add a column index to the list of sort columns and perform the multi-column sorting- SYNOPSIS
-
tablelist::addToSortColumns pathName columnIndex
- DESCRIPTION
- This command adds the column index specified by
columnIndex
to the list of sort columns of the tablelist widgetpathName
and sorts the items based on the elements of the columns indicated by the modified list. This is done by invoking thesortbycolumnlist
subcommand of the Tcl command associated with the given tablelist widget. The two arguments passed tosortbycolumnlist
are built as follows: (a) if the given column index is already contained in the widget's list of sort columns (returned by thesortcolumnlist
subcommand) then this list is left unchanged and the sort order list (returned by thesortorderlist
subcommand) is updated by toggling its corresponding element fromincreasing
todecreasing
and vice-versa; (b) otherwise the column index is appended to the list of sort columns and the valueincreasing
is appended to the list of sort orders. - After sorting the items by passing the two updated
lists to the
sortbycolumnlist
subcommand, the virtual event<<TablelistColumnsSorted>>
(note the plural form!) is generated. For Tk versions 8.5 or higher, this virtual event is generated with its-data
option set to a list consisting of the two above-mentioned updated lists passed tosortbycolumnlist
as arguments. The command returns the new sort order corresponding to the given column, asdecreasing
orincreasing
. - If the specified column's
-showlinenumbers
option has been set to true, then the actions described above are not performed and the return value is an empty string. tablelist::addToSortColumns
is usually specified as the value of the-labelcommand2
configuration option for a tablelist widget.- KEYWORDS
- tablelist, sort, column list, widget