Skip to content

Table

morphui.uix.dataview.table

TopLeftCorner(**kwargs)

Bases: MorphIdentificationBehavior, MorphThemeBehavior, MorphOverlayLayerBehavior, MorphSurfaceLayerBehavior, Widget

An empty cell for the top-left corner of the data view table.

BottomLeftCorner(**kwargs)

Bases: MorphIdentificationBehavior, Widget

An empty cell for the bottom-left corner of the data view table.

MorphDataViewTable(kw_header={}, kw_index={}, kw_body={}, kw_navigation={}, **kwargs)

Bases: MorphGridLayout

A data view table component with MorphUI styling and behavior.

This class provides a structured data view table with header, index, body, and navigation components. It supports pagination and customizable styling and behavior.

Examples:

Create a simple data view table with sample data:

from morphui.app import MorphApp
from morphui.uix.dataview.table import MorphDataViewTable
class TestApp(MorphApp):
    def build(self):
        table = MorphDataViewTable(
            rows_per_page=5,
            values=[
                ['Alice', '24', 'Engineer'],
                ['Bob', '30', 'Designer'],
                ['Charlie', '28', 'Teacher'],
                ['David', '35', 'Manager'],
                ['Eve', '22', 'Intern'],
                ['Frank', '29', 'Developer'],],
            column_names=['Name', 'Age', 'Occupation'],)
        return table
TestApp().run()

Create a larger data view table with more rows and custom row names: ```python from kivy.clock import Clock from morphui.app import MorphApp from morphui.uix.dataview import MorphDataViewTable

class MyApp(MorphApp): def build(self) -> MorphDataViewTable: self.theme_manager.theme_mode = 'Dark' self.theme_manager.seed_color = 'morphui_teal'

    self.table = MorphDataViewTable(
        rows_per_page=13,)

    Clock.schedule_once(self.set_data, 0)
    return self.table

def set_data(self, *args) -> None:
    self.table.column_names = [
        'Name', 'Age', 'Occupation', 'Country', 'Email', 'Phone', 'Company',
        'Position', 'Department', 'Start Date', 'End Date', 'Status',
        'Notes', 'Salary', 'Bonus', 'Manager', 'Team', 'Location',
        'Project', 'Task', 'Deadline', 'Priority', 'Comments', 'Feedback',
        'Rating', 'Score', 'Level', 'Experience', 'Skills', 'Certifications',
        'Languages', 'Hobbies', 'Interests', 'Social Media', 'Website',]
    self.table.values = [[
        f'Name {i}',
        str(20 + i % 30),
        'Occupation ' + str(i % 10),
        'Country ' + str(i % 5),
        'email' + str(i) + '@example.com',
        '123-456-7890',
        'Company ' + str(i % 7),
        'Position ' + str(i % 8),
        'Department ' + str(i % 6),
        '2020-01-01',
        '2023-12-31',
        'Active' if i % 2 == 0 else 'Inactive',
        'Notes for entry ' + str(i),
        str(50000 + (i % 10) * 5000),
        str(5000 + (i % 5) * 1000),
        'Manager ' + str(i % 4),
        'Team ' + str(i % 3),
        'Location ' + str(i % 6),
        'Project ' + str(i % 9),
        'Task ' + str(i % 12),
        '2023-12-' + str(10 + i % 20).zfill(2),
        'High' if i % 3 == 0 else 'Low',
        'Comments for entry ' + str(i),
        'Feedback for entry ' + str(i),
        str(1 + i % 5),
        str(50 + i % 50),
        str(1 + i % 4),
        str(1 + i % 10) + ' years',
        'Skill ' + str(i % 15),
        'Certification ' + str(i % 7),
        'Language ' + str(i % 5),
        'Hobby ' + str(i % 8),
        'Interest ' + str(i % 6),
        'http://socialmedia' + str(i) + '.com',
        'http://website' + str(i) + '.com',
        ]
        for i in range(1, 51)]
    self.table.row_names = [f'Row {i}' for i in range(1, 51)]

if name == "main": MyApp().run()

Initialize the data view table component.

rows_per_page = BoundedNumericProperty(10, min=1, errorvalue=1) class-attribute instance-attribute

The number of rows to display per page in the data view table.

Setting this property controls how many rows of data are shown on each page of the table. It must be at least 1.

:attr:rows_per_page is a :class:~kivy.properties.BoundedNumericProperty and defaults to 10.

current_page = AliasProperty(_get_current_page, _set_current_page, bind=['chunked_values']) class-attribute instance-attribute

The current page number being displayed in the data view table.

This property allows getting and setting the current page number displayed in the data view table. It is synchronized with the navigation component.

:attr:current_page is an :class:~kivy.properties.AliasProperty and is bound to changes in chunked_values.

values = ListProperty([]) class-attribute instance-attribute

2D list of values holding the data for the table.

This property allows getting and setting the values of the body cells in a tabular format. When set, it updates the body's data accordingly. The outer list represents rows, and each inner list represents the values in that row.

:attr:values is an :class:~kivy.properties.AliasProperty and defaults to an empty list.

column_names = AliasProperty(lambda self: self.header.column_names, lambda self, names: setattr(self.header, 'column_names', names)) class-attribute instance-attribute

List of column names for the data view table.

This property holds the names of the columns displayed in the header of the table. It can be set to customize the column headers.

:attr:column_names is a :class:~kivy.properties.ListProperty and defaults to an empty list.

row_names = ListProperty([]) class-attribute instance-attribute

List of row names for the data view table.

This property holds the names of the rows displayed in the index of the table. It can be set to customize the row headers.

:attr:row_names is a :class:~kivy.properties.ListProperty and defaults to an empty list.

chunked_values = ListProperty([]) class-attribute instance-attribute

List of values chunks based on rows_per_page.

This property holds the values divided into chunks, where each chunk corresponds to a page of values containing the specified number of rows.

:attr:chunked_values is an :class:~kivy.properties.AliasProperty and is bound to changes in values and rows_per_page.

page_values = AliasProperty(_get_page_values, bind=['chunked_values', 'current_page']) class-attribute instance-attribute

2D list of values for the current page in the table (read-only).

This property provides access to the values currently displayed in the body cells of the table for the current page.

:attr:page_values is an :class:~kivy.properties.AliasProperty and is bound to changes in chunked_values and current_page.

page_rows = AliasProperty(_get_page_rows, bind=['row_names', 'current_page', 'rows_per_page']) class-attribute instance-attribute

List of row names for the current page in the table (read-only).

This property provides access to the row names currently displayed in the index for the current page.

:attr:page_rows is an :class:~kivy.properties.AliasProperty and is bound to changes in row_names, current_page, and rows_per_page.

is_empty = AliasProperty(_get_is_empty, None, bind=['values', 'column_names', 'row_names']) class-attribute instance-attribute

Flag indicating whether the data view table is empty (read-only).

This property returns True if the table has no values, column names, or row names; otherwise, it returns False.

:attr:is_empty is an :class:~kivy.properties.AliasProperty and is bound to changes in values, column_names, and row_names.

default_config = dict(cols=2, size_hint=(1, 1), spacing=0, padding=0, theme_color_bindings={'normal_surface_color': 'surface_color'}) class-attribute instance-attribute

Default configuration for the MorphDataViewTable.

header = MorphDataViewHeader(identity='header', **kw_header) instance-attribute

The header component of the data view table.

index = MorphDataViewIndex(identity='index', **kw_index) instance-attribute

The index component of the data view table.

body = MorphDataViewBody(identity='body', header=(self.header), index=(self.index), **kw_body) instance-attribute

The body component of the data view table.

navigation = MorphDataViewNavigation(identity='navigation', **kw_navigation) instance-attribute

The navigation component of the data view table.

top_left = TopLeftCorner() instance-attribute

The top-left corner component of the data view table.

bottom_left = BottomLeftCorner() instance-attribute

The bottom-left corner component of the data view table.

update_chunked_values(*args)

Set the chunked values based on rows_per_page.

This method divides the full values into chunks according to the specified number of rows per page. Each chunk represents a page of data in the table. It also updates the navigation component with the current page and total pages.

This method is automatically called when the values or rows_per_page properties change.