MCPcopy Create free account
hub / github.com/cogentcore/core / SortColumn

Method SortColumn

core/table.go:397–426  ·  view source on GitHub ↗

SortColumn sorts the slice for the given field index. It toggles between ascending and descending if already sorting on this field.

(fieldIndex int)

Source from the content-addressed store, hash-verified

395// It toggles between ascending and descending if already
396// sorting on this field.
397func (tb *Table) SortColumn(fieldIndex int) {
398 sgh := tb.header
399 _, idxOff := tb.RowWidgetNs()
400
401 ascending := true
402
403 for fli := 0; fli < tb.numVisibleFields; fli++ {
404 hdr := sgh.Child(idxOff + fli).(*Button)
405 hdr.SetType(ButtonAction)
406 if fli == fieldIndex {
407 if tb.sortIndex == fli {
408 tb.sortDescending = !tb.sortDescending
409 ascending = !tb.sortDescending
410 } else {
411 tb.sortDescending = false
412 }
413 if ascending {
414 hdr.SetIcon(icons.KeyboardArrowUp)
415 } else {
416 hdr.SetIcon(icons.KeyboardArrowDown)
417 }
418 } else {
419 hdr.SetIcon("none")
420 }
421 }
422
423 tb.sortIndex = fieldIndex
424 tb.SortSlice()
425 tb.Update()
426}
427
428// sortFieldName returns the name of the field being sorted, along with :up or
429// :down depending on ascending or descending sorting.

Callers 1

makeHeaderMethod · 0.95

Implementers 1

_cogentcore_org_core_plot_plots_Tableyaegicore/symbols/cogentcore_org-core-

Calls 6

RowWidgetNsMethod · 0.95
SortSliceMethod · 0.95
ChildMethod · 0.80
SetIconMethod · 0.65
UpdateMethod · 0.65
SetTypeMethod · 0.45

Tested by

no test coverage detected