Blazor Hierarchical Grid Size

    The Ignite UI for Blazor Size feature in Blazor Hierarchical Grid allows users to control the spacing and layout of data within the IgbHierarchicalGrid. 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

    Blazor Hierarchical Grid Size Example

    Usage

    As you can see in the demo above, the IgbHierarchicalGrid 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);
    }
    
    <IgbHierarchicalGrid Class="gridSize" Data=northwindEmployees @ref=grid>
    </IgbHierarchicalGrid>
    

    And now let's see in details how each option reflects on the IgbHierarchicalGrid component. When you switch between different size options the height of each IgbHierarchicalGrid 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.

    • large - this is the default IgbHierarchicalGrid size with the lowest intense and row height equal to 50px. Left and Right paddings are 24px; Minimal column Width is 80px;
    • medium - this is the middle intense size with 40px row height. Left and Right paddings are 16px; Minimal column Width is 64px;
    • small - this is the size with highest intense and 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 the --ig-size is applied. Let's first add a button which will help us to switch between each size:

    <div class="options vertical">
        <IgbPropertyEditorPanel
        DescriptionType="WebHierarchicalGrid"
        IsHorizontal="true"
        IsWrappingEnabled="true"
        Name="PropertyEditor"
        @ref="propertyEditor">
            <IgbPropertyEditorPropertyDescription
            Name="SizeEditor"
            @ref="sizeEditor"
            Label="Grid Size:"
            ValueType="PropertyEditorValueType.EnumValue"
            DropDownNames="@(new string[] { "Small", "Medium", "Large" })"
            DropDownValues="@(new string[] { "Small", "Medium", "Large" })"
            ChangedScript="WebGridSetGridSize">
            </IgbPropertyEditorPropertyDescription>
        </IgbPropertyEditorPanel>
    </div>
    

    Now we can add the markup.

    <IgbHierarchicalGrid AutoGenerate="false" Name="hierarchicalGrid" @ref="hierarchicalGrid" Id="grid" AllowFiltering="true">
        <IgbColumn Field="CustomerID" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="CompanyName" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="ContactName" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="Address" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="City" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="PostalCode" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="Country" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="Phone" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="Fax" DataType="GridColumnDataType.String"></IgbColumn>
        
        <IgbRowIsland ChildDataKey="Orders" AutoGenerate="false">
            <IgbColumn Field="OrderID" DataType="GridColumnDataType.Number"></IgbColumn>
            <IgbColumn Field="EmployeeID" DataType="GridColumnDataType.Number"></IgbColumn>
            <IgbColumn Field="OrderDate" DataType="GridColumnDataType.Date"></IgbColumn>
            <IgbColumn Field="RequiredDate" DataType="GridColumnDataType.Date"></IgbColumn>
            <IgbColumn Field="ShippedDate" DataType="GridColumnDataType.Date"></IgbColumn>
            <IgbColumn Field="ShipVia" DataType="GridColumnDataType.Number"></IgbColumn>
            <IgbColumn Field="Freight" DataType="GridColumnDataType.Number"></IgbColumn>
            <IgbColumn Field="ShipName" DataType="GridColumnDataType.String"></IgbColumn>
            <IgbColumn Field="ShipAddress" DataType="GridColumnDataType.String"></IgbColumn>
            <IgbColumn Field="ShipCity" DataType="GridColumnDataType.String"></IgbColumn>
            <IgbColumn Field="ShipPostalCode" DataType="GridColumnDataType.String"></IgbColumn>
            <IgbColumn Field="ShipCountry" DataType="GridColumnDataType.String"></IgbColumn>
            
            <IgbRowIsland ChildDataKey="OrderDetails" AutoGenerate="false">
                <IgbColumn Field="ProductID" DataType="GridColumnDataType.Number"></IgbColumn>
                <IgbColumn Field="UnitPrice" DataType="GridColumnDataType.Number"></IgbColumn>
                <IgbColumn Field="Quantity" DataType="GridColumnDataType.Number"></IgbColumn>
                <IgbColumn Field="Discount" DataType="GridColumnDataType.Number"></IgbColumn>
            </IgbRowIsland>
        </IgbRowIsland>
    </IgbHierarchicalGrid>
    

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

    @code {
        *** In JavaScript ***
        igRegisterScript("WebGridSetGridSize", (sender, evtArgs) => {
            var newVal = evtArgs.newValue.toLowerCase();
            var grid = document.getElementById("grid");
            grid.style.setProperty('--ig-size', `var(--ig-size-${newVal})`);
        }, false);
    }
    

    Another option that IgbHierarchicalGrid provides for you, in order to be able to change the height of the rows in the IgbHierarchicalGrid, is the property RowHeight. So let's see in action how this property affects the IgbHierarchicalGrid 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 RowHeight specified.
    • --ig-size will affect all of the rest elements in the Hierarchical Grid, as it has been described above.

    We can now extend our sample and add RowHeight property to the IgbHierarchicalGrid:

    <IgbHierarchicalGrid
       @ref="grid"
       Id="grid"
       Class="gridSize"
       Width="100%"
       Height="100%"
       AutoGenerate="true"
       Data="northwindEmployees"
       RowHeight="rowHeight">
    </IgbHierarchicalGrid>
    
    @code {
       private string rowHeight = "80px";
    }
    

    API References

    Our community is active and always welcoming to new ideas.