Get help from the marimo community

Updated 2 months ago

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

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