Skip to content

Add column sorting support to the Table component#124

Merged
Oleg-Melnik merged 11 commits into
masterfrom
table-sorting
Apr 15, 2026
Merged

Add column sorting support to the Table component#124
Oleg-Melnik merged 11 commits into
masterfrom
table-sorting

Conversation

@Oleg-Melnik
Copy link
Copy Markdown
Collaborator

@Oleg-Melnik Oleg-Melnik commented Apr 14, 2026

This PR adds column sorting support to the table component, including sortable column definitions, sorting state management, and interactive table header behavior.

Below is an example of a typical usage scenario:

class UsersTable : Table<User>() {

    init {
        columns = listOf(
            TableColumn(
                name = "Name",
                sorting = TableColumnSorting(compareBy(User::name))
            ) { user ->
                Text(user.name)
            },
            TableColumn(
                name = "Created",
                sorting = TableColumnSorting(
                    comparator = compareBy(User::createdAt),
                    initialDirection = DESCENDING
                )
            ) { user ->
                Text(user.createdAt)
            }
        )
    }
}

@Oleg-Melnik Oleg-Melnik self-assigned this Apr 14, 2026
@Oleg-Melnik Oleg-Melnik changed the title Support table sorting Add column sorting support to the Table component Apr 14, 2026
@Oleg-Melnik Oleg-Melnik marked this pull request as ready for review April 15, 2026 10:06
@Oleg-Melnik Oleg-Melnik requested review from armiol and dpikhulya April 15, 2026 10:06
Copy link
Copy Markdown
Contributor

@armiol armiol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Oleg-Melnik please see some minor comments.

* @param column The column whose header content should be displayed.
* @param sortingState The current interactive sorting state of the table.
*/
// The Pointer Hover API is experimental in the current version of Compose (1.5.2).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it a part of the documentation section, not a standalone comment. To me it looks like an implementation note.

* with information about headers.
* @param sortingState The current interactive sorting state of the table.
*/
// The Pointer Hover API is experimental in the current version of Compose (1.5.2).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as below.

/**
* Holds interactive sorting state for a [Table].
*
* This class encapsulates sorting transitions so that the table component stays focused on
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of this paragraph altogether. If you read it, you may find it really tells nothing except "this is a software component that is designed as a class in OOP-style code".

/**
* Stores the current interactive sorting state for the table.
*
* The state is separated into a dedicated object so that sorting rules and UI interactions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please kill this paragraph. It is obvious for humans. Not for agents, apparently.

@Oleg-Melnik Oleg-Melnik requested a review from armiol April 15, 2026 10:55
@Oleg-Melnik Oleg-Melnik merged commit e9ab7e0 into master Apr 15, 2026
5 of 6 checks passed
@Oleg-Melnik Oleg-Melnik deleted the table-sorting branch April 15, 2026 11:11
Copy link
Copy Markdown
Contributor

@dpikhulya dpikhulya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Oleg-Melnik LGTM in general with a small potential improvement.

FYI: I've also created an issue that might be relevant in context of sorting or later if/when the table gets more column-related features: #125

Comment on lines +207 to +208
* This comparator is applied when the user has not selected a sortable header,
* if one is available.
Copy link
Copy Markdown
Contributor

@dpikhulya dpikhulya Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be nice if this defaultComparator also served as a fallback sorting direction even if column sorting is active — for the cases when any column comparator interprets items as equal. In this case this would be a second-level criterion that defines item sorting in such indefinite cases.

This could practically be useful when sorting by categorical columns (e.g. statuses, etc.), in which case many rows would turn out to be "equal" according to the column's comparator alone.

If it works that way already (I didn't check it), maybe just worth documenting it here for clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants