kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.22k stars 671 forks source link

Not possible to srot first column in MDDataTable #1566

Open oliverbrace opened 11 months ago

oliverbrace commented 11 months ago

So it looks like it is not possible to apply column sorting to the first column of a table

from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable
from kivymd.uix.screen import MDScreen

class Example(MDApp):
    def build(self):
        self.data_tables = MDDataTable(
            use_pagination=True,
            check=True,
            column_data=[
                ("No.", dp(30), self.sort_col_1),
                ("Team Lead", dp(30), self.sort_col_2),
            ],
            row_data=[
                ("1", "Chase Nguyen"),
                ("2", "Brie Furman"),
                ("3", "Jeremy lake"),
                ("4", "Angelica Howards"),
                ("5", "Diane Okuma"),
            ],
            elevation=2,
        )
        screen = MDScreen()
        screen.add_widget(self.data_tables)
        return screen

    def sort_col_1(self, data):
        return zip(*sorted(enumerate(data), key=lambda l: l[1][0]))

    def sort_col_2(self, data):
        return zip(*sorted(enumerate(data), key=lambda l: l[1][1]))

Example().run()

The second column has the sort icon but the first one does not.

oliverbrace commented 11 months ago

My workaround is just to make a column I don't mind not being able to sort into the first column