Get help from the marimo community

Updated 3 months ago

Sorting tables elements that are not fully strings, floats or ints

At a glance
The community member is looking for a way to sort tables that contain numeric values, while also adding a colorbar in the cell. However, the addition of the colorbar prevents the elements from being sorted. The community member would prefer a solution that allows sorting, rather than placing the colorbar in a separate column. A comment suggests using a custom format_mapping to keep the value the same but add the color in the format function, or using custom ordering on the object itself. However, there is no explicitly marked answer.
Useful resources
Hi. I'm looking to sort tables that contain values which are numeric, but to help the user, I want to add a colorbar in the cell. Because I do that the elements can no longer be sorted. Is there a workaround to allow the cells to be sorted still? I would rather that, than placing colorbar in a separate column. This goes for any type of composite type of cell really. It would be great if you could still sort (given some condition that is sortable).
Attachment
image.png
M
1 comment
Not currently. I would suggest another column.

You could try:
  1. Custom format_mapping. Keep the value the same, but add the color in the format function:
Plain Text
table = mo.ui.table(
        data=[
            {"first_name": "Michael", "last_name": "Scott", "age": 45},
        ],
        format_mapping={
            "first_name": format_name,  # Use callable to format
        },
    )


  1. Custom ordering on the object itself. see https://www.geeksforgeeks.org/sorting-objects-of-user-defined-class-in-python/
Add a reply
Sign up and join the conversation on Discord