jupyter-widgets / ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
BSD 3-Clause "New" or "Revised" License
579 stars 51 forks source link

Hide columns in DataGrid #339

Open ccd2796 opened 2 years ago

ccd2796 commented 2 years ago

It would be nice to be able to hide columns when displaying the DataGrid. I am working with a DataFrame that has lots of columns not relevant to the user, but useful for calculations. So it would be helpful to be able to hide those columns, get the input from the user (who will edit the cells), and store all that info with DataGrid.data

ibdafna commented 2 years ago

Hello @ccd2796 🙋‍♂️and welcome to the ipydatagrid community! Would you be interested in helping implement this feature?

ccd2796 commented 2 years ago

Sent you an IB!

jgunstone commented 2 years ago

this is something that @ollyhensby and I are interested in also... is this where the lumino table definitions are defined: https://github.com/bloomberg/ipydatagrid/blob/fcd6a9399942dbb425904cd740272db30c88a99c/ipydatagrid/datagrid.py#L481-L482

or rather, would editing __dataframe_reference_index_names and __dataframe_reference_columns change the UI view?

ibdafna commented 2 years ago

I think it should be relatively easy to add this functionality on the Python side. We would just need to set the width of the column to 0. The only thing we need to figure out is the best way of un/doing this from the GUI. The references above will not affect the lumino definitions - they're used to restore pandas' native indices when retrieving the data back from the front-end.

jgunstone commented 1 year ago

reinvigorating this chat as i'd still love to be able to hide a column without changing the underlying data...

import pandas as pd
from ipydatagrid import DataGrid

df = pd.DataFrame.from_dict({"a":[1,2], "b":[3,4]})
gr = DataGrid(df)
gr

image

gr.column_widths = {"a":0}
# nothing happens
gr.column_widths = {"a":1}
# width reverts to minimum value of 10

image

this is called to update to column_widths https://github.com/bloomberg/ipydatagrid/blob/c7cf3a48756264db92218ac40a0d5417a078dc9a/js/feathergrid.ts#L832-L868

ultimately calling a resize command in the core lumino package. this.grid.resizeColumn('body', i, colSize)

I'd like to be able override whatever sets the minimum col width to 10 such that it allows a column_width = 0 as this would effectively hide the column.

but I couldn't find the code that did that in this repo... ?

I had a look in the base lumino package and found this: https://github.com/jupyterlab/lumino/blob/a817cb2d05ac264403ad930fb9c038746c5393ff/packages/datagrid/src/datagrid.ts#L86-L88

but again can't find where the minimum column width number (=10) is actually set...! Lumino has a minimumSizes class which feels like I'm getting warm...

if anyone can point me in the right direction I'd be v grateful

zwelz3 commented 6 months ago

I don't have the knowledge to contribute, but this would be a nice enhancement (I came here after trying to set column_width to 0).

Would be doubly nice if it also overrides the auto_fit_columns flag (so you can use both)