[GH-ISSUE #871] Could TableCell.SetClickedFunc callback pass a ref to *TableCell? #634

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

Originally created by @carpii on GitHub (Aug 26, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/871

Issue #470 resulted in TableCell.SetClickedFunc() being added

This allows you to provide a callback fn, when a cell is clicked (even if it is unselectable)

The issue is, the callback provides no way to identify which cell was clicked (and it cannot be retrieved from Table.GetSelection() if the cell is unselectable. Also I suspect this event is triggered before the selection would be updated anyway).

This makes it very difficult to attach a generic click handler to all your header cells - for example if you wanted to install the same callback for all your header cells, then use TableCell.GetReference() to decide how to sort the table

Not sure if I'm missing something, but is there a way to identify the cell which was clicked?

Could the tableCell be passed as a parameter to the callback fn?

Originally created by @carpii on GitHub (Aug 26, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/871 Issue #470 resulted in `TableCell.SetClickedFunc()` being added This allows you to provide a callback fn, when a cell is clicked (even if it is unselectable) The issue is, the callback provides no way to identify which cell was clicked (and it cannot be retrieved from `Table.GetSelection()` if the cell is unselectable. Also I suspect this event is triggered before the selection would be updated anyway). This makes it very difficult to attach a generic click handler to all your header cells - for example if you wanted to install the same callback for all your header cells, then use `TableCell.GetReference()` to decide how to sort the table Not sure if I'm missing something, but is there a way to identify the cell which was clicked? Could the tableCell be passed as a parameter to the callback fn?
kerem closed this issue 2026-03-04 01:06:39 +03:00
Author
Owner

@carpii commented on GitHub (Aug 27, 2023):

Good catch, thanks!

Just updating your example, since width is now returned, and callback must return a bool..

func getCallBackFor(tc *tview.TableCell)(func () bool){
    return func() bool{
        // i have handle to the tablecell now
        tc.ScratchNuts()
        row,col,width := tc.GetLastPosition()
        return false
    }
}
<!-- gh-comment-id:1694754975 --> @carpii commented on GitHub (Aug 27, 2023): Good catch, thanks! Just updating your example, since width is now returned, and callback must return a bool.. ```go func getCallBackFor(tc *tview.TableCell)(func () bool){ return func() bool{ // i have handle to the tablecell now tc.ScratchNuts() row,col,width := tc.GetLastPosition() return false } } ```
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#634
No description provided.