quantopian/qgrid

Sorting columns by other values than those shown

deeplook opened this issue · 0 comments

Environment

  • Operating System: Mac OS Mojave 10.14.6
  • Python Version: 3.8.0
  • How did you install Qgrid: conda
  • Python packages: $ pip freeze or $ conda list (please include qgrid, notebook, and jupyterlab versions)
    jupyterlab                2.2.8                      py_0    conda-forge
    jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
    jupyterlab_server         1.2.0                      py_0    conda-forge 
    notebook                  6.1.4            py38h32f6830_1    conda-forge
    qgrid                     1.3.1            py38h32f6830_1    conda-forge
    
  • Jupyter lab packages (if applicable): $ jupyter labextension list
    @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
          @jupyter-widgets/jupyterlab-sidecar v0.5.0  enabled  OK
          jupyter-leaflet v0.13.2  enabled  OK
          jupyter-vue v1.4.1  enabled  OK
          qgrid2 v1.1.3  enabled  OK
    

Description of Issue

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...

  • What did you expect to happen?

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

  • What happened instead?

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.