[GH-ISSUE #1093] Need help with grid and table #794

Open
opened 2026-03-04 01:07:48 +03:00 by kerem · 2 comments
Owner

Originally created by @TLINDEN on GitHub (May 3, 2025).
Original GitHub issue: https://github.com/rivo/tview/issues/1093

I am trying to use this library which seems to be easy to use and understand. However, I'm having two problems and I didn't find anything in the documentation which could help.

This is the sample code I'm using. It creates a two column grid which contains a table on the left column.

One problem is, that I'd like the table to fill the whole column, something like width: 100% in CSS. The other problem is that it seems to be impossible to add cell spacing. I didn't find a solution for both.

I'd appreciate any help with thes issues!

Many thanks in advance,
Tom

Originally created by @TLINDEN on GitHub (May 3, 2025). Original GitHub issue: https://github.com/rivo/tview/issues/1093 I am trying to use this library which seems to be easy to use and understand. However, I'm having two problems and I didn't find anything in the documentation which could help. [This is the sample code I'm using](https://gist.github.com/TLINDEN/13a9ccd55ed3a848eaada3999cec4ff8). It creates a two column grid which contains a table on the left column. One problem is, that I'd like the table to fill the whole column, something like `width: 100%` in CSS. The other problem is that it seems to be impossible to add cell spacing. I didn't find a solution for both. I'd appreciate any help with thes issues! Many thanks in advance, Tom
Author
Owner

@manuecg commented on GitHub (May 21, 2025):

Hi, have you tried this?
func (data *Data) GetCell(row, column int) *tview.TableCell { return tview.NewTableCell(data.Rows[row][column]).SetExpansion(1) }

Image

<!-- gh-comment-id:2898302059 --> @manuecg commented on GitHub (May 21, 2025): Hi, have you tried this? `func (data *Data) GetCell(row, column int) *tview.TableCell { return tview.NewTableCell(data.Rows[row][column]).SetExpansion(1) }` ![Image](https://github.com/user-attachments/assets/dc9a9cfc-75b5-4732-a555-8e141adf500c)
Author
Owner

@TLINDEN commented on GitHub (May 28, 2025):

Sorry for the late reply. Yes, SetExpansion(1) did the trick.

But I've got another problem: I want the table to have a header. So my idea was to put the header captions as row[0] and set the first row as non-selectable. However, it seems to be impossible to do that. The only thing I came up with was this:

table.SetContent(data).SetFixed(0, 0)
for column, _ := range rows[0] {
	table.GetCell(0, column).SetSelectable(false)
}

But it doesn't work, the first row is still selectable.

Edited to add:

I managed to fix this, I replaced table.SetContent(data).SetFixed(0, 0) with:

	var headers = []string{
		"Vorname",
		"Nachname",
		"Geburtsjahr",
	}

	for column, header := range headers {
		table.SetCell(0, column, tview.NewTableCell(header).SetSelectable(false))
	}

	for row, entry := range rows {
		for column, cell := range entry {
			table.SetCell(row+1, column, tview.NewTableCell(cell))
		}
	}

Now I have a non-selectable table header. However, now the table is not expanded anymore:

Image

Here's the gist of the changed example

<!-- gh-comment-id:2915883595 --> @TLINDEN commented on GitHub (May 28, 2025): Sorry for the late reply. Yes, `SetExpansion(1)` did the trick. But I've got another problem: I want the table to have a header. So my idea was to put the header captions as row[0] and set the first row as non-selectable. However, it seems to be impossible to do that. The only thing I came up with was this: ```golang table.SetContent(data).SetFixed(0, 0) for column, _ := range rows[0] { table.GetCell(0, column).SetSelectable(false) } ``` But it doesn't work, the first row is still selectable. **Edited to add:** I managed to fix this, I replaced `table.SetContent(data).SetFixed(0, 0)` with: ```golang var headers = []string{ "Vorname", "Nachname", "Geburtsjahr", } for column, header := range headers { table.SetCell(0, column, tview.NewTableCell(header).SetSelectable(false)) } for row, entry := range rows { for column, cell := range entry { table.SetCell(row+1, column, tview.NewTableCell(cell)) } } ``` Now I have a non-selectable table header. However, now the table is not expanded anymore: ![Image](https://github.com/user-attachments/assets/4cbeea8c-ef8f-4dfe-ad2a-7a96e1cb42a9) [Here's the gist of the changed example](https://gist.github.com/TLINDEN/726b9f15031463737842d9aa278e3c4e)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#794
No description provided.