Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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

KV = """
Screen:
    MDDataTable:
        id: datatable
        rows_num: 5
        check: True
        column_data:
            [("Name", 100), ("Age", 50)]
        row_data:
            [("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)

TestApp().run()

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.