bloomberg/ipydatagrid

grid.auto_fit_columns not working

joseberlines opened this issue ยท 12 comments

I got the code from the example related to auto_fit_columns and I get the following:

image

As you see the code is the same as in:
https://github.com/bloomberg/ipydatagrid/blob/main/examples/Column%20Width%20Auto-Fit.ipynb
but I changed just one line to make the words langer.

The result is that applying:
grid.auto_fit_columns = True

does not change anything and the content of the cells is cut as if nothing would have been changed.

Some idea what I am doing wrong?

THIS IS WHAT i WOULD HAE EXPECTED:
image

thanks

Hello @joseberlines , I tested this functionality locally and it appears to be working fine. Can you check your installation, perhaps you're on an older version?

auto_fit_columns

@joseberlines can you check the browser console and let me know if you see any errors there?

I will report soon. we have ipydatagrid in a JupyterHub environement and indeed the version currently is not the last one.

Hi @ibdafna
So version updated to 1.1.11 and this is the result:
image

code gist:
https://gist.github.com/joseberlines/694259ce8299e179cdc1877e6baaccbd

What I find strange:
a) the auto ajustment does not work fully. The table is created first small and when running:
g.auto_fit_columns = True
columns are getting more width but not entirely.

b) Since wraptext = True I would expect al least to go over several lines WITHIN a cell.

Putting info all together (and even if I am mixing up two things here)

  1. I am looking for a way to auto adjust all the content of all the cells.
  2. Ideally there should/could be a way to tell ipydatagrid: max width is 90px (or whatever) and from there wrap the text contained in a cell into new lines within the cell.

This would be pretty much like Excel and it would be a great enhancement.

Moreover, in the above code I made the rows bigger as this:
image

And the way autofit columns works together with wrap text is puzzeling.
We had this issue still open here:
#210 & #294

but following instructions there I thought the wrapping would be working.

Please let me know if you need/want more information or insights regarding my explanation

I can reproduce this easily by copying the code from the example notebook posted above, and adjusting the column contents to long values instead of the given short values. @ibdafna The GIF you showed shows resizing only by the column headers. The problem is when wanting to resize by the column contents.

I'm using version 1.1.11 and I don't see any errors in the console. Thanks!

Screenshot -
I would expect "col1" to be resized based on the cell contents.

image

(Perhaps this is simply a missing feature)

@matangover Okay, yes, the auto sizing works only based on the columns, not the cells. I misunderstood the question. @joseberlines looking at your screenshot, you have the text_wrap feature set to true on the header_renderer TextRenderer object, which applies only to the column headers. You need to set this for the default renderer. You can use default_renderer = <some_textrenderer_instance> if you want to this apply to all cells. Or you can do this based on a column. I believe the documentation has a few examples. Thanks!

@ibdafna, would it be possible to have some sort of option that will allow auto-adjusting the length of the columns based on the content rather than the column headers?

Effectively, I'm looking for what you get in Excel when double clicking the line that splits two adjacent rows in Excel.

At first, this can be provided through a programmatic API, but ideally, it would be great to auto-adjust the length by double clicking on the GUI.

I could start implementing this myself if you don't morally disagree with the change.

Added jupyterlab/lumino#546 that implements the functionality described in this.

vtgruk commented

jupyterlab/lumino#546 is now released in JupyterLab https://github.com/jupyterlab/jupyterlab/releases/tag/v4.0.5 . I think we can now close this issue.

Closing as it's now possible to double click on the column separators to auto-fit content, thanks a lot @vthemelis !