SetColOrder sets the exhibition order of the specified column. The previous column which has the specified order will have the original column order.
(colid string, order int)
| 424 | // The previous column which has the specified order will have |
| 425 | // the original column order. |
| 426 | func (t *Table) SetColOrder(colid string, order int) { |
| 427 | |
| 428 | // Checks column id |
| 429 | c := t.header.cmap[colid] |
| 430 | if c == nil { |
| 431 | panic(tableErrInvCol) |
| 432 | } |
| 433 | // Checks exhibition order |
| 434 | if order < 0 || order > len(t.header.cols) { |
| 435 | panic(tableErrInvRow) |
| 436 | } |
| 437 | // Find the exhibition order for the specified column |
| 438 | for ci := 0; ci < len(t.header.cols); ci++ { |
| 439 | if t.header.cols[ci] == c { |
| 440 | // If the order of the specified column is the same, nothing to do |
| 441 | if ci == order { |
| 442 | return |
| 443 | } |
| 444 | // Swap column orders |
| 445 | prev := t.header.cols[order] |
| 446 | t.header.cols[order] = c |
| 447 | t.header.cols[ci] = prev |
| 448 | break |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | // Recalculates the header and all rows |
| 453 | t.recalc() |
| 454 | } |
| 455 | |
| 456 | // EnableColResize enable or disables if the specified column can be resized by the |
| 457 | // user using the mouse. |