SortColumn sorts the specified column interpreting its values as strings or numbers and sorting in ascending or descending order. This sorting is independent of the sort configuration of column set when the table was created
(col string, asString bool, asc bool)
| 642 | // and sorting in ascending or descending order. |
| 643 | // This sorting is independent of the sort configuration of column set when the table was created |
| 644 | func (t *Table) SortColumn(col string, asString bool, asc bool) { |
| 645 | |
| 646 | c := t.header.cmap[col] |
| 647 | if c == nil { |
| 648 | panic(tableErrInvCol) |
| 649 | } |
| 650 | if len(t.rows) < 2 { |
| 651 | return |
| 652 | } |
| 653 | if asString { |
| 654 | ts := tableSortString{rows: t.rows, col: c.order, asc: asc, format: c.format} |
| 655 | sort.Sort(ts) |
| 656 | } else { |
| 657 | ts := tableSortNumber{rows: t.rows, col: c.order, asc: asc} |
| 658 | sort.Sort(ts) |
| 659 | } |
| 660 | t.recalc() |
| 661 | } |
| 662 | |
| 663 | // setRow sets the value of all the cells of the specified row from |
| 664 | // the specified map indexed by column id. |