ToTable to export the datatable to a csv-like struct
(opt ...ExportOption)
| 56 | |
| 57 | // ToTable to export the datatable to a csv-like struct |
| 58 | func (t *DataTable) ToTable(opt ...ExportOption) [][]interface{} { |
| 59 | if t == nil { |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | opts := newExportOptions(opt...) |
| 64 | if err := t.evaluateExpressions(); err != nil { |
| 65 | panic(err) |
| 66 | } |
| 67 | |
| 68 | rows := make([][]interface{}, 0, t.nrows+1) |
| 69 | |
| 70 | // visible columns |
| 71 | var headers []interface{} |
| 72 | var cols []int |
| 73 | for i, col := range t.cols { |
| 74 | if opts.WithHiddenCols || col.IsVisible() { |
| 75 | cols = append(cols, i) |
| 76 | headers = append(headers, col.Name()) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | rows = append(rows, headers) |
| 81 | for i := 0; i < t.nrows; i++ { |
| 82 | r := make([]interface{}, 0, len(cols)) |
| 83 | for _, pos := range cols { |
| 84 | r = append(r, t.cols[pos].serie.Get(i)) |
| 85 | } |
| 86 | rows = append(rows, r) |
| 87 | } |
| 88 | return rows |
| 89 | } |
| 90 | |
| 91 | // Schema describes a datatable |
| 92 | type Schema struct { |