[GH-ISSUE #470] Question. How to handle a mouse click on a table cell #337

Closed
opened 2026-03-04 01:04:08 +03:00 by kerem · 6 comments
Owner

Originally created by @LazarenkoA on GitHub (Jul 15, 2020).
Original GitHub issue: https://github.com/rivo/tview/issues/470

The task is to perform some actions when clicking on a cell in the table heading, for example, sorting by the current column, how to implement this?

PS
I tried searching in the documentation, did not find

Originally created by @LazarenkoA on GitHub (Jul 15, 2020). Original GitHub issue: https://github.com/rivo/tview/issues/470 The task is to perform some actions when clicking on a cell in the table heading, for example, sorting by the current column, how to implement this? PS I tried searching in the documentation, did not find
kerem closed this issue 2026-03-04 01:04:08 +03:00
Author
Owner

@LazarenkoA commented on GitHub (Jul 16, 2020):

i found, SetMouseCapture

<!-- gh-comment-id:659273594 --> @LazarenkoA commented on GitHub (Jul 16, 2020): i found, SetMouseCapture
Author
Owner

@LazarenkoA commented on GitHub (Jul 16, 2020):

just don't know how to get a cell by position

<!-- gh-comment-id:659327937 --> @LazarenkoA commented on GitHub (Jul 16, 2020): just don't know how to get a cell by position
Author
Owner

@rivo commented on GitHub (Aug 18, 2020):

There is the Table.SetSelectionChangedFunc() which you can use. The callback will receive the position of the clicked cell.

Let me know if this helps.

<!-- gh-comment-id:675425814 --> @rivo commented on GitHub (Aug 18, 2020): There is the [`Table.SetSelectionChangedFunc()`](https://pkg.go.dev/github.com/rivo/tview?tab=doc#Table.SetSelectionChangedFunc) which you can use. The callback will receive the position of the clicked cell. Let me know if this helps.
Author
Owner

@LazarenkoA commented on GitHub (Aug 18, 2020):

Thanks, but it will not work for my case, I click on the table header, but it is set for it SetSelectable(false)

<!-- gh-comment-id:675456893 --> @LazarenkoA commented on GitHub (Aug 18, 2020): Thanks, but it will not work for my case, I click on the table header, but it is set for it SetSelectable(false)
Author
Owner

@rivo commented on GitHub (Sep 15, 2020):

I understand. Makes sense. I've added TableCell.SetClickedFunc(). That should help you implement the sorting function in your table.

<!-- gh-comment-id:692648159 --> @rivo commented on GitHub (Sep 15, 2020): I understand. Makes sense. I've added [`TableCell.SetClickedFunc()`](https://godoc.org/github.com/rivo/tview#TableCell.SetClickedFunc). That should help you implement the sorting function in your table.
Author
Owner

@LazarenkoA commented on GitHub (Sep 17, 2020):

I have 2 questions ☺

  1. I do go get -u "github.com/gdamore/tcell@master" but I don't see the method SetClickedFunc().
  2. how can I find out the cell position? I can't call the current cell from the function (it is got as a parameter)
<!-- gh-comment-id:694175917 --> @LazarenkoA commented on GitHub (Sep 17, 2020): I have 2 questions ☺ 1. I do `go get -u "github.com/gdamore/tcell@master"` but I don't see the method `SetClickedFunc()`. 2. how can I find out the cell position? I can't call the current cell from the function (it is got as a parameter)
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#337
No description provided.