From ec8d64b4bee11c7da7e6fb0c8e34afd256fcc3f7 Mon Sep 17 00:00:00 2001 From: Vladimir Markelov Date: Fri, 30 Jun 2017 16:49:20 -0700 Subject: [PATCH] added hot key to sort tableview column --- tableview.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tableview.go b/tableview.go index b77c412..8104581 100644 --- a/tableview.go +++ b/tableview.go @@ -16,9 +16,10 @@ Predefined hotkeys: Home, End - move cursor to first and last column, respectively Alt+Home, Alt+End - move cursor to first and last row, respectively PgDn, PgUp - move cursor to a screen down and up - Enter, F2 - emits event TableActionEdit ( + Enter, F2 - emits event TableActionEdit Insert - emits event TableActionNew Delete - emits event TableActionDelete + F4 - Change sort mode Events: OnDrawCell - called every time the table is going to draw a cell. @@ -796,6 +797,27 @@ func (l *TableView) ProcessEvent(event Event) bool { ev := TableEvent{Action: TableActionNew, Col: l.selectedCol, Row: l.selectedRow} go l.onAction(ev) } + case term.KeyF4: + if l.onAction != nil { + colID := l.selectedCol + sort := l.columns[colID].Sort + + for idx := range l.columns { + l.columns[idx].Sort = SortNone + } + + if sort == SortAsc { + sort = SortDesc + } else if sort == SortNone { + sort = SortAsc + } else { + sort = SortNone + } + l.columns[colID].Sort = sort + + ev := TableEvent{Action: TableActionSort, Col: colID, Row: -1, Sort: sort} + l.onAction(ev) + } default: return false }