Called by the TableView to sort the model.
(col int, order walk.SortOrder)
| 80 | |
| 81 | // Called by the TableView to sort the model. |
| 82 | func (m *FooModel) Sort(col int, order walk.SortOrder) error { |
| 83 | m.sortColumn, m.sortOrder = col, order |
| 84 | |
| 85 | sort.SliceStable(m.items, func(i, j int) bool { |
| 86 | a, b := m.items[i], m.items[j] |
| 87 | |
| 88 | c := func(ls bool) bool { |
| 89 | if m.sortOrder == walk.SortAscending { |
| 90 | return ls |
| 91 | } |
| 92 | |
| 93 | return !ls |
| 94 | } |
| 95 | |
| 96 | switch m.sortColumn { |
| 97 | case 0: |
| 98 | return c(a.Index < b.Index) |
| 99 | |
| 100 | case 1: |
| 101 | return c(a.Bar < b.Bar) |
| 102 | |
| 103 | case 2: |
| 104 | return c(a.Baz < b.Baz) |
| 105 | |
| 106 | case 3: |
| 107 | return c(a.Quux.Before(b.Quux)) |
| 108 | } |
| 109 | |
| 110 | panic("unreachable") |
| 111 | }) |
| 112 | |
| 113 | return m.SorterBase.Sort(col, order) |
| 114 | } |
| 115 | |
| 116 | func (m *FooModel) ResetRows() { |
| 117 | // Create some random data. |