quantopian / qgrid

An interactive grid for sorting, filtering, and editing DataFrames in Jupyter notebooks
Apache License 2.0
3.04k stars 425 forks source link

Sorting columns by other values than those shown #346

Open deeplook opened 3 years ago

deeplook commented 3 years ago

Environment

I show numeric values formatted in columns such that they become clickable hyperlinks, think GitLab project IDs pointing to the respective webpage, using something like f'<a href="http://foo.com/project/{id}">{id}</a>'which works, but...

When sorting by that column I would hope to see the value of the original values (numeric or string) preserved.

Instead, when I sort by the respective column, the values are (of course) no longer correctly sorted, and I see numeric (clickable) values ordered like 20, 3, 500, instead of 3, 20, 500.

Reproduction Steps

import pandas as pd
import qgrid

data = [(f'<a href="http://foo.com/{a}">{a}</a>', b, c)
    for [a, b, c] in [(500, 2, 3), (3, 3, 4), (20, 4, 5)]
]
df = pd.DataFrame(data, columns=["A", "B", "C"])
qgrid.show_grid(df)
# then sort by column "A"

What steps have you taken to resolve this already?

I can workaround this only by adding another data column without formatting to a hyperlink, but that looks questionable and superfluous for regular users. It would be nicer to indicate the original values by which some column should be sorted in some other way.