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()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder