mirror of
https://github.com/rivo/tview.git
synced 2025-04-30 13:48:50 +08:00
Added row/column removal functions to Table. Resolves #174
This commit is contained in:
parent
ebf651d1c0
commit
8cf347b745
25
table.go
25
table.go
@ -431,6 +431,31 @@ func (t *Table) GetCell(row, column int) *TableCell {
|
|||||||
return t.cells[row][column]
|
return t.cells[row][column]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveRow removes the row at the given position from the table. If there is
|
||||||
|
// no such row, this has no effect.
|
||||||
|
func (t *Table) RemoveRow(row int) *Table {
|
||||||
|
if row < 0 || row >= len(t.cells) {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
t.cells = append(t.cells[:row], t.cells[row+1:]...)
|
||||||
|
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveColumn removes the column at the given position from the table. If
|
||||||
|
// there is no such column, this has no effect.
|
||||||
|
func (t *Table) RemoveColumn(column int) *Table {
|
||||||
|
for row := range t.cells {
|
||||||
|
if column < 0 || column >= len(t.cells[row]) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t.cells[row] = append(t.cells[row][:column], t.cells[row][column+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
// GetRowCount returns the number of rows in the table.
|
// GetRowCount returns the number of rows in the table.
|
||||||
func (t *Table) GetRowCount() int {
|
func (t *Table) GetRowCount() int {
|
||||||
return len(t.cells)
|
return len(t.cells)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user