DataTables

Data tables display sets of data across rows and columns.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-previous.png

Warning

Data tables are still far from perfect. Errors are possible and we hope you inform us about them.

API - kivymd.uix.datatables

class kivymd.uix.datatables.MDDataTable(**kwargs)
Events
on_row_press

Called when a table row is clicked.

on_check_press

Called when the check box in the table row is checked.

Use events as follows

from kivy.metrics import dp

from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable


class Example(MDApp):
    def build(self):
        self.data_tables = MDDataTable(
            size_hint=(0.9, 0.6),
            use_pagination=True,
            check=True,
            column_data=[
                ("No.", dp(30)),
                ("Column 1", dp(30)),
                ("Column 2", dp(30)),
                ("Column 3", dp(30)),
                ("Column 4", dp(30)),
                ("Column 5", dp(30)),
            ],
            row_data=[
                (f"{i + 1}", "2.23", "3.65", "44.1", "0.45", "62.5")
                for i in range(50)
            ],
        )
        self.data_tables.bind(on_row_press=self.on_row_press)
        self.data_tables.bind(on_check_press=self.on_check_press)

    def on_start(self):
        self.data_tables.open()

    def on_row_press(self, instance_table, instance_row):
        '''Called when a table row is clicked.'''

        print(instance_table, instance_row)

    def on_check_press(self, instance_table, current_row):
        '''Called when the check box in the table row is checked.'''

        print(instance_table, current_row)


Example().run()
column_data

Data for header columns.

from kivy.metrics import dp

from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable


class Example(MDApp):
    def build(self):
        self.data_tables = MDDataTable(
            size_hint=(0.9, 0.6),
            # name column, width column
            column_data=[
                ("Column 1", dp(30)),
                ("Column 2", dp(30)),
                ("Column 3", dp(30)),
                ("Column 4", dp(30)),
                ("Column 5", dp(30)),
                ("Column 6", dp(30)),
            ],
        )

    def on_start(self):
        self.data_tables.open()


Example().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-column-data.png

column_data is an ListProperty and defaults to [].

row_data

Data for rows.

from kivy.metrics import dp

from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable


class Example(MDApp):
    def build(self):
        self.data_tables = MDDataTable(
            size_hint=(0.9, 0.6),
            column_data=[
                ("Column 1", dp(30)),
                ("Column 2", dp(30)),
                ("Column 3", dp(30)),
                ("Column 4", dp(30)),
                ("Column 5", dp(30)),
                ("Column 6", dp(30)),
            ],
            row_data=[
                # The number of elements must match the length
                # of the `column_data` list.
                ("1", "2", "3", "4", "5", "6"),
                ("1", "2", "3", "4", "5", "6"),
            ],
        )

    def on_start(self):
        self.data_tables.open()


Example().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-row-data.png

row_data is an ListProperty and defaults to [].

sort

Whether to display buttons for sorting table items.

sort is an BooleanProperty and defaults to False.

check

Use or not use checkboxes for rows.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-check.gif

check is an BooleanProperty and defaults to False.

use_pagination

Use page pagination for table or not.

from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable


class Example(MDApp):
    def build(self):
        self.data_tables = MDDataTable(
            size_hint=(0.9, 0.6),
            use_pagination=True,
            column_data=[
                ("No.", dp(30)),
                ("Column 1", dp(30)),
                ("Column 2", dp(30)),
                ("Column 3", dp(30)),
                ("Column 4", dp(30)),
                ("Column 5", dp(30)),
            ],
            row_data=[
                (f"{i + 1}", "1", "2", "3", "4", "5") for i in range(50)
            ],
        )

    def on_start(self):
        self.data_tables.open()


Example().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-use-pagination.png

use_pagination is an BooleanProperty and defaults to False.

rows_num

The number of rows displayed on one page of the table.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-use-pagination.gif

rows_num is an NumericProperty and defaults to 10.

pagination_menu_pos

Menu position for selecting the number of displayed rows. Available options are ‘center’, ‘auto’.

Center

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-pos-center.png

Auto

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-pos-auto.png

pagination_menu_pos is an OptionProperty and defaults to ‘center’.

pagination_menu_height

Menu height for selecting the number of displayed rows.

140dp

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-height-140.png

240dp

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-height-240.png

pagination_menu_height is an NumericProperty and defaults to ‘140dp’.

background_color

Background color in the format (r, g, b, a). See background_color.

background_color is a ListProperty and defaults to [0, 0, 0, .7].

on_row_press(self, *args)

Called when a table row is clicked.

on_check_press(self, *args)

Called when the check box in the table row is checked.

create_pagination_menu(self, interval)