Documentation
¶
Overview ¶
Package sort can be used to sort an array by their columns in either ascending or descending order.
Calling
sort.SortEntries(columnMap, entries, []string{"node", "-time"})
for example sorts the array by the time column in descending order and afterwards by the node column.
The "-" prefix means the sorter should use descending order. Sorting by multiple fields will be done from the last field to the first in a stable way - so the first column always gets the highest priority.
Three special cases exist:
- Non-existent columns will be silently ignored.
- When a virtual column is selected as a column to sort by, that column will be silently ignored.
- A column with a custom extractor is allowed to sort by. But the sorting function uses the underlying value instead of the result of the extractor function
One can use sort.CanSortBy(columnMap, []string{"node", "-time"}) to check if any column will be silently ignored. For more information the function sort.FilterSortableColumns(columnMap, []string{"node", "-time"}) can be used, which returns two lists. One with all valid filterable columns and another one with the invalid columns
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanSortBy ¶ added in v0.11.0
CanSortBy returns true, if all requested sortBy arguments can be used for sorting This is not the case for a virtual column, which has no underlying value type
func FilterSortableColumns ¶ added in v0.11.0
FilterSortableColumns returns returns two lists, one containing the valid column names and another containing the invalid column names.
func SortEntries ¶
SortEntries sorts entries by applying the sortBy rules from right to left (first rule has the highest priority). The rules are strings containing the column names, optionally prefixed with "-" to switch to descending sort order.
Types ¶
type ColumnSorterCollection ¶
type ColumnSorterCollection[T any] struct { // contains filtered or unexported fields }
func Prepare ¶
func Prepare[T any](cols columns.ColumnMap[T], sortBy []string) *ColumnSorterCollection[T]
Prepare prepares a sorter collection that can be re-used for multiple calls to Sort() for efficiency. Filter rules will be applied from right to left (first rule has the highest priority).
func (*ColumnSorterCollection[T]) Sort ¶
func (csc *ColumnSorterCollection[T]) Sort(entries []*T)