Close
Angular React Web Components Blazor Web Components
Premium

Web Components Tree Grid Column Resizing Overview

The Ignite UI for Web Components Column Resizing feature in Web Components Tree Grid allows users to easily adjust the width of the columns of the IgcTreeGrid. By default, they will see a temporary resize indicator while the drag resizing operation is in effect. There are several resizing options available - Resizing Columns in Pixels/Percentages, Restrict Column Resizing, Auto-Size Columns on Double Click, and Auto-Size Columns on Initialization.

Web Components Tree Grid Column Resizing Example

Column resizing is also enabled per-column level, meaning that the IgcTreeGrid can have a mix of resizable and non-resizable columns. This is done via the Column.resizable input of the Column.

<igc-column field="ID" width="100px" resizable="true"></igc-column>

You can subscribe to the IgcGridComponentEventMap.columnResized event of the IgcTreeGrid to implement some custom logic when a column is resized. Both, previous and new column widths, as well as the Column object, are exposed through the event arguments.

<igc-tree-grid id="treeGrid" auto-generate="false" primary-key="ID" foreign-key="ParentID">
    <igc-column field="Title" width="100px" resizable="true"></igc-column>
    <igc-column field="HireDate" width="100px" resizable="true"></igc-column>
</igc-tree-grid>
constructor() {
    var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
    treeGrid.data = this.data;
    treeGrid.columnResized = this.onResize;
}

public onResize(event) {
    this.col = event.column;
    this.pWidth = event.prevWidth;
    this.nWidth = event.newWidth;
}

Resizing Columns in Pixels/Percentages

Depending on the user scenario, the column width may be defined in pixels, percentages or a mix of both. All these scenarios are supported by the Column Resizing feature. By default if a column does not have width set, it fits the available space with width set in pixels.

This means that the following configuration is possible:

<igc-tree-grid id="data" primary-key="ID" foreign-key="ParentID" auto-generate="false">
    <igc-column field="Title" resizable="true" width="10%"></igc-column>
    <igc-column field="HireDate" resizable="true" width="100px"></igc-column>
    <igc-column field="Age" data-type="number" resizable="true"></igc-column>
</igc-tree-grid>

There is a slight difference in the way resizing works for columns set in pixels and percentages.

Pixels

Resizing columns with width in pixels works by directly adding or subtracting the horizontal amount of the mouse movement from the size of the column.

Percentages

When resizing columns with width in percentages, the horizontal amount of the mouse movement in pixels translates roughly to its percentage amount relative to the grid width. The columns remain responsive and any future grid resizing will still reflect on the columns as well.

Restrict Column Resizing

You can also configure the minimum and maximum allowable column widths. This is done via the Column.minWidth and IgcColumnState.maxWidth inputs of the Column. In this case the resize indicator drag operation is restricted to notify the user that the column cannot be resized outside the boundaries defined by Column.minWidth and IgcColumnState.maxWidth.

<igc-column field="ID" width="100px" resizable="true"
            min-width="60px" max-width="230px"></igc-column>

Mixing the minimum and maximum column width value types (pixels or percentages) is allowed. If the values set for minimum and maximum are set to percentages, the respective column size will be limited to those exact sizes similar to pixels.

This means the following configurations are possible:

<igc-column field="ID" width="10%" resizable="true"
            min-width="60px" max-width="230px"></igc-column>

or

<igc-column field="ID" width="100px" resizable="true"
            min-width="5%" max-width="15%"></igc-column>

Auto-Size Columns on Double Click

Each column can be auto sized by double clicking the right side of the header - the column will be sized to the longest currently visible cell value, including the header itself. This behavior is enabled by default, no additional configuration is needed. However, the column will not be auto-sized in case IgcColumnState.maxWidth is set on that column and the new width exceeds that IgcColumnState.maxWidth value. In this case the column will be sized according to preset IgcColumnState.maxWidth value.

You can also auto-size a column dynamically using the exposed Column.autosize method on Column.

constructor() {
    var id = this.id = document.getElementById('ID') as IgcColumnComponent;
    id.autosize();
}

Auto-Size Columns on Initialization

Each column can be set to auto-size on initialization by setting IgcTreeGrid.width to ‘auto’:

<igc-column width='auto'></igc-column>

When the column is first initialized in the view it resolves its width to the size of the longest visible cell or header. Note that cells that are outside of the visible rows are not included.

This approach is more performance optimized than auto-sizing post initialization and is recommended especially in cases where you need to auto-size a large number of columns.

Styling

In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties. In case you would like to change the color of the resize handle, you need to set a class for the grid first:

<igc-tree-grid class="grid"></igc-tree-grid>

Then set the related CSS property for that class:

.grid {
    --ig-grid-resize-line-color: #f35b04;
}

Demo

API References

Additional Resources

Our community is active and always welcoming to new ideas.