Close
Angular React Web Components Blazor Web Components
Premium

Web Components Tree Grid Size

The Ignite UI for Web Components Size feature in Web Components Tree Grid allows users to control the spacing and layout of data within the IgcTreeGrid. By changing --ig-size, you can significantly improve the user experience when interacting with large amounts of content. They can choose from three size options:

  • --ig-size-large
  • --ig-size-medium
  • --ig-size-small

Web Components Tree Grid Size Example

Usage

As you can see in the demo above, the IgcTreeGrid provides three size options: small, medium and large. The code snippet below shows how to set --ig-size either inline or part of a CSS class:

.gridSize {
    --ig-size: var(--ig-size-medium);
}
<igc-tree-grid id="grid" class="gridSize">
</igc-tree-grid>

And now let’s see in details how each option reflects on the IgcTreeGrid component. When you switch between different size options the height of each IgcTreeGrid element and the corresponding paddings will be changed. Also if you want to apply custom column IgcTreeGrid.width, please consider the fact that it must be bigger than the sum of left and right padding:

  • large - this is the default IgcTreeGrid size with the lowest intense and row height equal to 50px. Left and Right paddings are 24px; Minimal column IgcTreeGrid.width is 80px;
  • medium - this is the middle intense size with 40px row height. Left and Right paddings are 16px; Minimal column IgcTreeGrid.width is 64px;
  • small - this is the size with highest intense and 32px row height. Left and Right paddings are 12px; Minimal column IgcTreeGrid.width is 56px;

Please keep in mind that currently you can not override any of the sizes.

Let’s now continue with our sample and see in action how the --ig-size is applied. Let’s first add a button which will help us to switch between each size:

<div class="size-chooser">
    <igc-property-editor-panel
    description-type="WebTreeGrid"
    is-horizontal="true"
    is-wrapping-enabled="true"
    name="PropertyEditor"
    id="propertyEditor">
        <igc-property-editor-property-description
        name="SizeEditor"
        id="SizeEditor"
        label="Grid Size:"
        value-type="EnumValue"
        drop-down-names="Small, Medium, Large"
        drop-down-values="Small, Medium, Large">
        </igc-property-editor-property-description>
    </igc-property-editor-panel>
</div>

Now we can add the markup.

<igc-tree-grid id="grid" primary-key="ID" foreign-key="ParentID" width="100%"
    height="550px" allow-filtering="true">
    <igc-column field="Name" data-type="string" sortable="true" has-summary="true" width="200px"></igc-column>
    <igc-column-group pinned="false" header="General Information">
        <igc-column field="HireDate" data-type="date" sortable="true" has-summary="true">
        </igc-column>
        <igc-column-group header="Person Details">
            <igc-column field="ID" data-type="number" filterable="false"></igc-column>
            <igc-column field="Title" data-type="string" sortable="true" has-summary="true"></igc-column>
            <igc-column field="Age" data-type="number" sortable="true" has-summary="true" filterable="false"></igc-column>
        </igc-column-group>
    </igc-column-group>
    <igc-column-group header="Address Information">
        <igc-column-group header="Location">
            <igc-column field="Country" data-type="string" sortable="true" has-summary="true"></igc-column>
            <igc-column field="City" data-type="string" sortable="true" has-summary="true"></igc-column>
            <igc-column field="Address" data-type="string" sortable="true" has-summary="true"></igc-column>
        </igc-column-group>
        <igc-column-group header="Contact Information">
            <igc-column field="Phone" data-type="string" sortable="true" has-summary="true"></igc-column>
            <igc-column field="Fax" data-type="string" sortable="true" has-summary="true"></igc-column>
            <igc-column field="PostalCode" data-type="string" sortable="true" has-summary="true"></igc-column>
        </igc-column-group>
    </igc-column-group>
    <igc-column-group header="Address Information">
        <igc-column-group header="Location">
            <igc-column field="Country" data-type="string" sortable="true" has-summary="true"></igc-column>
            <igc-column field="City" data-type="string" sortable="true" has-summary="true"></igc-column>
            <igc-column field="Address" data-type="string" sortable="true" has-summary="true"></igc-column>
        </igc-column-group>
        <igc-column-group header="Contact Information">
            <igc-column field="Phone" data-type="string" sortable="true" resizable="true"></igc-column>
            <igc-column field="Fax" data-type="string" sortable="true" resizable="true"></igc-column>
            <igc-column field="PostalCode" data-type="string" sortable="true" resizable="true"></igc-column>
        </igc-column-group>
    </igc-column-group>
</igc-tree-grid>

Finally, let’s provide the necessary logic in order to actually apply the size:

constructor() {
    var propertyEditor = this.propertyEditor = document.getElementById('PropertyEditor') as IgcPropertyEditorPanelComponent;
    var sizeEditor = this.sizeEditor = document.getElementById('SizeEditor') as IgcPropertyEditorPropertyDescriptionComponent;
    var grid = this.grid = document.getElementById('grid') as IgcTreeGrid;
    propertyEditor.componentRenderer = this.renderer;
    propertyEditor.target = this.grid;
    this.webGridSetGridSize = this.webGridSetGridSize.bind(this);
    sizeEditor.changed = this.webGridSetGridSize;
    grid.data = this.data;
}

private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
    if (this._componentRenderer == null) {
        this._componentRenderer = new ComponentRenderer();
        var context = this._componentRenderer.context;
        PropertyEditorPanelDescriptionModule.register(context);
        WebGridDescriptionModule.register(context);
    }
    return this._componentRenderer;
}

public webGridSetGridSize(sender: any, args: IgcPropertyEditorPropertyDescriptionChangedEventArgs): void {
    var newVal = (args.newValue as string).toLowerCase();
    var grid = document.getElementById("grid");
    grid.style.setProperty('--ig-size', `var(--ig-size-${newVal})`);
}

Another option that IgcTreeGrid provides for you, in order to be able to change the height of the rows in the IgcTreeGrid, is the property IgcTreeGrid.rowHeight. So let’s see in action how this property affects the IgcTreeGrid layout along with the --ig-size.

Please keep in mind the following:

  • --ig-size CSS variable will have no impact on row height if there is IgcTreeGrid.rowHeight specified.
  • --ig-size will affect all of the rest elements in the Tree Grid, as it has been described above.

We can now extend our sample and add IgcTreeGrid.rowHeight property to the IgcTreeGrid:

<igc-tree-grid id="grid" class="gridSize" row-height="80px" width="100%" height="550px" allow-filtering="true">
</igc-tree-grid>

API References

Additional Resources

Our community is active and always welcoming to new ideas.