added hot key to sort tableview column

This commit is contained in:
Vladimir Markelov 2017-06-30 16:49:20 -07:00
parent 4425b1bdb7
commit ec8d64b4be

View File

@ -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
}