DataTables¶
See also
Data tables display sets of data across rows and columns.
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_pressCalled when a table row is clicked.
on_check_pressCalled 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()
column_datais anListPropertyand 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()
row_datais anListPropertyand defaults to [].
-
sort¶ Whether to display buttons for sorting table items.
sortis anBooleanPropertyand defaults to False.
-
check¶ Use or not use checkboxes for rows.
checkis anBooleanPropertyand 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()
use_paginationis anBooleanPropertyand defaults to False.
-
rows_num¶ The number of rows displayed on one page of the table.
rows_numis anNumericPropertyand defaults to 10.
Menu position for selecting the number of displayed rows. Available options are ‘center’, ‘auto’.
Center
Auto
pagination_menu_posis anOptionPropertyand defaults to ‘center’.
Menu height for selecting the number of displayed rows.
140dp
240dp
pagination_menu_heightis anNumericPropertyand defaults to ‘140dp’.
-
background_color¶ Background color in the format (r, g, b, a). See
background_color.background_coloris aListPropertyand 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.