Ask Your Question

How can I use kivymd md datatable to automatically check the checkbox when I click on a row?

asked 2021-11-26 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-01-19 00:00:00 +0000

woof gravatar image

You can use the on_row_press event of the MDDataTable to toggle the checkbox of the corresponding row. Here's an example:

from import MDApp
from kivy.lang.builder import Builder
from kivymd.uix.datatables import MDDataTable

KV = """
        id: datatable
        rows_num: 5
        check: True
            [("Name", 100), ("Age", 50)]
            [("John", 25), ("Jane", 30), ("Bob", 40), ("Alice", 35), ("Jack", 20)]
        on_row_press: self.toggle_check_row(args[1])

class TestApp(MDApp):
    def build(self):
        return Builder.load_string(KV)


In the example, the MDDataTable has the check attribute set to True which enables the checkboxes for each row. The on_row_press event is assigned to the toggle_check_row method of the MDDataTable which toggles the checkbox of the corresponding row when it is pressed.

Note that the args[1] parameter passed to the toggle_check_row method is the index of the pressed row. This index can be used to access the active_cells list of the MDDataTable and toggle the checkbox of the corresponding row.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2021-11-26 11:00:00 +0000

Seen: 10 times

Last updated: Jan 19 '22