[GH-ISSUE #323] Getting a selectionChanged notify when application uses Table.Select() #244

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

Originally created by @pktgen on GitHub (Jul 19, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/323

Using a Table if I move the selected row/col via keyboard and I have the SetSelectionChangedFunc() the callback works great.

In my case I need to remove or add items to the table. This may mean the I need to change the selected row/col in the application. It would be nice to get a notification or callback called when I call the Table.Select() function.

I could not find anything in the docs about getting some callback for this type of event. As a test I went into the Table.Select() function and modified it to do this:

func (t *Table) Select(row, column int) *Table {
      t.selectedRow, t.selectedColumn = row, column

       // If the selection has changed, notify the handler.
       if t.selectionChanged != nil &&
               (t.rowsSelectable || t.columnsSelectable) {
               t.selectionChanged(t.selectedRow, t.selectedColumn)
       }
       return t
}

Do you think this is a reasonable change to get a notify call when the application moves to a different cell?

BTW, excellent package :-)

Originally created by @pktgen on GitHub (Jul 19, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/323 Using a Table if I move the selected row/col via keyboard and I have the SetSelectionChangedFunc() the callback works great. In my case I need to remove or add items to the table. This may mean the I need to change the selected row/col in the application. It would be nice to get a notification or callback called when I call the Table.Select() function. I could not find anything in the docs about getting some callback for this type of event. As a test I went into the Table.Select() function and modified it to do this: ```go func (t *Table) Select(row, column int) *Table { t.selectedRow, t.selectedColumn = row, column // If the selection has changed, notify the handler. if t.selectionChanged != nil && (t.rowsSelectable || t.columnsSelectable) { t.selectionChanged(t.selectedRow, t.selectedColumn) } return t } ``` Do you think this is a reasonable change to get a notify call when the application moves to a different cell? BTW, excellent package :-)
kerem closed this issue 2026-03-04 01:03:18 +03:00
Author
Owner

@rivo commented on GitHub (Jul 21, 2019):

Thanks for catching this. It should have triggered this event all along. The latest commit fixes this.

<!-- gh-comment-id:513556610 --> @rivo commented on GitHub (Jul 21, 2019): Thanks for catching this. It should have triggered this event all along. The latest commit fixes this.
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#244
No description provided.