SortColumn sorts the slice for the given field index. It toggles between ascending and descending if already sorting on this field.
(fieldIndex int)
| 395 | // It toggles between ascending and descending if already |
| 396 | // sorting on this field. |
| 397 | func (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. |
no test coverage detected