Search code examples
javagridgxt

GXT grid auto columns width


I have a GXT Grid and want the columns in it to fit to the screen. here what my grid looks like now: enter image description here

It looks so because I've set the concrete values for widths of the columns, which fits to my screen. And I'd like columns automatically fit to the grid's width


Solution

  • The Javadoc is pretty clear about this :

    Grids support several ways to manage column widths:

    1. The most basic approach is to simply give pixel widths to each column. Columns widths will match the specified values.
    2. A column can be identified as an auto-expand column. As the width of the grid changes, or columns are resized, the specified column's width is adjusted so that the column fills the available width with no horizontal scrolling. See GridView.setAutoExpandColumn(ColumnConfig).
    3. The grid can resize columns based on relative weights, determined by the pixel width assigned to each column. As the width of the grid or columns change, the weight is used to allocate the available space. Use GridView.setAutoFill(boolean) or GridView.setForceFit(boolean) to enable this feature:
      • With auto fill, the calculations are run when the grid is created (or reconfigured). After the grid is rendered, the column widths will not be adjusted when the available width changes.
      • With force fit the width calculations are run every time there are changes to the available width or column sizes.
    4. To prevent a column from participating in auto fill or force fit, use ColumnConfig.setFixed(boolean).