Author Topic: Dynamic column minimum width  (Read 3612 times)

ksoerens

  • Newbie
  • *
  • Posts: 4
    • View Profile
Dynamic column minimum width
« on: November 05, 2014, 06:21:29 pm »
I need the grid to be able to adjust its columns to their minimum width. What I mean is, each column must have a width, which is at least as wide as the title or the content - depending on which one is widest. Neither the title, nor the content must break the line if spaces occur.

If I resize the window, so it gets smaller than the grid, the grid must still keep its minimum size, but then it can be scrolled by a horizontal scroll bar which will be visible in this case.

If I resize the window, so it gets BIGGER than the grid, the grid must increase each column width, like when the Fluid Laout is used.

Basically most of the functionality is already provided by the Fluid Layout. But is there any way to achieve what I want?

Thanks in advance for your reply!  :)

 

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Dynamic column minimum width
« Reply #1 on: November 05, 2014, 10:04:06 pm »
The grid width ( option.width ) can be described in px, %, %+-px and auto, so if you keep width in % and auto, grid changes its size as the window is resized. It's to be noted that % and auto are calculated based upon the grid immediate parent element's width.

grid also has an option minWidth so that the grid can't be shrunk beyond a certain minimum width.

If you want the columns to grow and shrink as the grid is resized due to window resize, then specify column widths in % ( column.width )

Setting the column widths equal to the content width without text wrap is not supported currently.

ksoerens

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dynamic column minimum width
« Reply #2 on: November 07, 2014, 01:05:08 pm »
Thanks for the reply.

So I had to solve it the hard way by running through the cells for each column and measuring the text size, including the title, and after that setting the minWidth to the largest size found.

The code is attached to events like Create and CellSave. And I also run the code when one or more rows are deleted manually. So now the horizontal scroll bar appears before the text gets wrapped when resizing the window.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Dynamic column minimum width
« Reply #3 on: November 07, 2014, 01:58:58 pm »
change event is an universal event whenever there is any change of data after initial load of data, so it could be a better fit for your case.

Horizontal scroll bar in the grid can be avoided with flexWidth: true if you don't want the horizontal scrollbar in grid.
« Last Edit: November 07, 2014, 02:15:28 pm by paramquery »