Sort the table
(by ...SortBy)
| 45 | |
| 46 | // Sort the table |
| 47 | func (t *DataTable) Sort(by ...SortBy) *DataTable { |
| 48 | cpy := t.Copy() |
| 49 | |
| 50 | if len(by) == 0 { |
| 51 | return cpy |
| 52 | } |
| 53 | |
| 54 | for i := range by { |
| 55 | b := &by[i] |
| 56 | // Check if column exists |
| 57 | b.index = t.ColumnIndex(b.Column) |
| 58 | if b.index < 0 { |
| 59 | return cpy |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | srt := &sorter{ |
| 64 | t: cpy, |
| 65 | by: by, |
| 66 | } |
| 67 | |
| 68 | sort.Sort(srt) |
| 69 | return cpy |
| 70 | } |