In this video I’ll show you how to add pagination to your data table with KivyMD and Python.
Pagination for datatables is incredibly important, and using pagination with kivymd is very easy. I’ll show you how to do it in this video. We’ll also look at customizing the pagination by number of rows, position, and color…sort of…
#kivy #codemy
Python Code: table2.py
GitHub Code: table2.py
from kivy.lang import Builder from kivymd.app import MDApp from kivymd.uix.screen import Screen from kivymd.uix.datatables import MDDataTable from kivy.metrics import dp # Display Pixles class MainApp(MDApp): def build(self): # Define Screen screen = Screen() # Define Table table = MDDataTable( pos_hint = {'center_x': 0.5, 'center_y': 0.5}, size_hint =(0.9, 0.6), check = True, use_pagination = True, rows_num = 3, pagination_menu_height = '240dp', pagination_menu_pos = "auto", background_color = [1,0,0,.5], column_data = [ ("First Name", dp(30)), ("Last Name", dp(30)), ("Email Address", dp(30)), ("Phone Number", dp(30)) ], row_data = [ ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ("John", "Elder", "[email protected]", "(123) 456-7891"), ("Mary", "Elder", "[email protected]", "(123) 456-1123"), ] ) # Bind the table table.bind(on_check_press=self.checked) table.bind(on_row_press=self.row_checked) self.theme_cls.theme_style = "Light" self.theme_cls.primary_palette = "BlueGray" #return Builder.load_file('table.kv') # Add table widget to screen screen.add_widget(table) return screen # Function for check presses def checked(self, instance_table, current_row): print(instance_table, current_row) # Function for row presses def row_checked(self, instance_table, instance_row): print(instance_table, instance_row) MainApp().run()
Add comment