[GH-ISSUE #841] how can i add a DropDown into table? #611

Closed
opened 2026-03-04 01:06:26 +03:00 by kerem · 1 comment
Owner

Originally created by @zhouruisong on GitHub (Apr 20, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/841

code as below, i can show DropDown in a table
please tell me the right way to show a DropDown in a table

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()

	// 创建一个表格
	table := tview.NewTable().
		SetBorders(true).
		SetSelectable(true, false)

	// 创建一个下拉菜单
	selectList := tview.NewDropDown().
		SetLabel("Select an item: ").
		SetOptions([]string{"Item 1", "Item 2", "Item 3"}, nil)

	// 将下拉菜单添加到表格的单元格中
	table.SetCell(0, 0, tview.NewTableCell("Row 1, Column 1")).
		SetCell(0, 1, tview.NewTableCell("Row 1, Column 2")).
		SetCell(1, 0, tview.NewTableCell("Row 2, Column 1")).
		SetCell(1, 1, tview.NewTableCell("Row 2, Column 2")).
		SetCell(2, 0, tview.NewTableCell("Row 3, Column 1")).
		SetCell(2, 1, tview.NewTableCell("Row 3, Column 2")).
		SetCell(3, 0, tview.NewTableCell("Row 4, Column 1")).
		SetCell(3, 1, tview.NewTableCell("Select an item:").SetExpansion(1).SetSelectable(false).
			SetAlign(tview.AlignCenter).SetTextColor(tview.Styles.SecondaryTextColor).
			SetBackgroundColor(tview.Styles.ContrastBackgroundColor).SetReference(selectList))

	if err := app.SetRoot(table, true).Run(); err != nil {
		panic(err)
	}
}

image

Originally created by @zhouruisong on GitHub (Apr 20, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/841 code as below, i can show DropDown in a table please tell me the right way to show a DropDown in a table ``` package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() // 创建一个表格 table := tview.NewTable(). SetBorders(true). SetSelectable(true, false) // 创建一个下拉菜单 selectList := tview.NewDropDown(). SetLabel("Select an item: "). SetOptions([]string{"Item 1", "Item 2", "Item 3"}, nil) // 将下拉菜单添加到表格的单元格中 table.SetCell(0, 0, tview.NewTableCell("Row 1, Column 1")). SetCell(0, 1, tview.NewTableCell("Row 1, Column 2")). SetCell(1, 0, tview.NewTableCell("Row 2, Column 1")). SetCell(1, 1, tview.NewTableCell("Row 2, Column 2")). SetCell(2, 0, tview.NewTableCell("Row 3, Column 1")). SetCell(2, 1, tview.NewTableCell("Row 3, Column 2")). SetCell(3, 0, tview.NewTableCell("Row 4, Column 1")). SetCell(3, 1, tview.NewTableCell("Select an item:").SetExpansion(1).SetSelectable(false). SetAlign(tview.AlignCenter).SetTextColor(tview.Styles.SecondaryTextColor). SetBackgroundColor(tview.Styles.ContrastBackgroundColor).SetReference(selectList)) if err := app.SetRoot(table, true).Run(); err != nil { panic(err) } } ``` ![image](https://user-images.githubusercontent.com/18162573/233292488-38ed4301-aa75-4d1a-bb32-4cc7eef40b58.png)
kerem closed this issue 2026-03-04 01:06:27 +03:00
Author
Owner

@rivo commented on GitHub (May 27, 2023):

There is no way to place a widget such as a DropDown in a table cell. You would have to place it somewhere outside the table.

<!-- gh-comment-id:1565370461 --> @rivo commented on GitHub (May 27, 2023): There is no way to place a widget such as a DropDown in a table cell. You would have to place it somewhere outside the table.
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#611
No description provided.