Angular Tree Grid Size

    IgxTreeGrid design is based on Material Design Guidelines. We currently provide an option to choose between predefined set of size options that will bring a small, medium, or large view respectively. By selecting the right size for your Material UI table / Material UI grid you can significantly improve the user experience when interacting with large amounts of content.

    Angular Tree Grid Size Example

    Usage

    As you can see in the demo above, the IgxTreeGrid provides three size options: small, medium and large. The code snippet below shows how to set size:

    <igx-tree-grid #treeGrid [data]="data" style="--ig-size: var(--ig-size-small)">
    </igx-tree-grid>
    

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

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

    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 each size is applied. Let's first add a button which will help us to switch between each size:

    <div class="density-chooser">
        <igx-buttongroup [values]="sizes"></igx-buttongroup>
    </div>
    
    @ViewChild(IgxButtonGroupComponent) public buttonGroup: IgxButtonGroupComponent;
    public size = 'small';
    public sizes;
    
    public ngOnInit() {
        this.sizes = [
            {
                label: 'small',
                selected: this.size === 'small',
                togglable: true
            },
            {
                label: 'medium',
                selected: this.sie === 'medium',
                togglable: true
            },
            {
                label: 'large',
                selected: this.size === 'large',
                togglable: true
            }
        ];
    }
    

    Now we can add the markup.

    <div class="density-chooser">
        <igx-buttongroup [values]="sizes" (selected)="selectSize($event)"></igx-buttongroup>
    </div>
    <igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID" width="100%"
        height="550px" [allowFiltering]="true">
        <igx-column field="Name" dataType="string" [sortable]="true" [hasSummary]="true" width="200px"></igx-column>
        <igx-column-group [pinned]="false" header="General Information">
            <igx-column field="HireDate" dataType="date" [sortable]="true" [hasSummary]="true">
                <ng-template igxCell let-cell="cell" let-val>
                    {{val | date:'dd/MM/yyyy'}}
                </ng-template>
            </igx-column>
            <igx-column-group header="Person Details">
                <igx-column field="ID" dataType="number" [filterable]="false"></igx-column>
                <igx-column field="Title" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
                <igx-column field="Age" dataType="number" [sortable]="true" [hasSummary]="true"
                    [summaries]="numberSummaries" [filterable]="false"></igx-column>
            </igx-column-group>
        </igx-column-group>
        <igx-column-group header="Address Information">
            <igx-column-group header="Location">
                <igx-column field="Country" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
                <igx-column field="City" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
                <igx-column field="Address" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
            </igx-column-group>
            <igx-column-group header="Contact Information">
                <igx-column field="Phone" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
                <igx-column field="Fax" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
                <igx-column field="PostalCode" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
            </igx-column-group>
        </igx-column-group>
        <igx-column-group header="Address Information">
            <igx-column-group header="Location">
                <igx-column field="Country" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
                <igx-column field="City" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
                <igx-column field="Address" dataType="string" [sortable]="true" [hasSummary]="true"></igx-column>
            </igx-column-group>
            <igx-column-group header="Contact Information">
                <igx-column field="Phone" dataType="string" [sortable]="true" [resizable]="true"></igx-column>
                <igx-column field="Fax" dataType="string" [sortable]="true" [resizable]="true"></igx-column>
                <igx-column field="PostalCode" dataType="string" [sortable]="true" [resizable]="true"></igx-column>
            </igx-column-group>
        </igx-column-group>
    </igx-tree-grid>
    

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

    @ViewChild('treeGrid', { read: IgxTreeGridComponent })
    public treeGrid: IgxTreeGridComponent;
    
    public selectSize(event: any) {
        this.size = this.sizes[event.index].label;
    }
    
    
    @HostBinding('style.--ig-size')
    protected get sizeStyle() {
        return `var(--ig-size-${this.size})`;
    }
    

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

    Please keep in mind the following:

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

    And now we can extend our sample and add rowHeight property to the Tree Grid:

    <igx-tree-grid #treeGrid [data]="data" [rowHeight]="'80px'" width="100%" 
    height="550px" [allowFiltering]="true">
    ..............
    </igx-tree-grid>
    

    API References

    Additional Resources

    Our community is active and always welcoming to new ideas.