Descripción general de los encabezados de varias columnas de la cuadrícula jerárquica Blazor

    The Ignite UI for Blazor Multi-Column Headers feature in Blazor Hierarchical Grid allows you to group columns by placing them under a common multi-header. Each multi-column headers group in the IgbHierarchicalGrid could be a representation of combinations between other groups or columns. This feature is particularly useful when dealing with large datasets where scrolling horizontally might be cumbersome.

    Blazor Hierarchical Grid Multi-Column Headers Example

    The declaration of multi-column headers is achieved by wrapping a set of columns into an IgbColumnGroup component with Header title information passed.

    <IgbHierarchicalGrid Data="HierarchicalCustomers" Name="hierarchicalGrid" @ref="hierarchicalGrid" Id="hierarchicalGrid" PrimaryKey="ID" Moving="true" AllowFiltering="true">
        <IgbColumn Field="CustomerID" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumnGroup Header="Address Information">
            <IgbColumnGroup Header="Location">
                <IgbColumn Field="Address" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="City" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="PostalCode" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="Country" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
            </IgbColumnGroup>
            <IgbColumnGroup Header="Contact Information">
                <IgbColumn Field="Phone" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="Fax" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
            </IgbColumnGroup>
        </IgbColumnGroup>
    </IgbHierarchicalGrid>
    

    Para alcanzarn-th el nivel de encabezados anidados, debe seguirse la declaración anterior. Así que anidarIgbColumnGroup conduce al resultado deseado.

    <IgbHierarchicalGrid Data="HierarchicalCustomers" Name="hierarchicalGrid" @ref="hierarchicalGrid" Id="hierarchicalGrid" PrimaryKey="ID" Moving="true" AllowFiltering="true">
        <IgbColumn Field="CustomerID" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumnGroup Header="General Information">
            <IgbColumn Field="CompanyName" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
            <IgbColumnGroup Header="Person Details">
                <IgbColumn Field="ContactName" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="ContactTitle" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
            </IgbColumnGroup>
        </IgbColumnGroup>
    </IgbHierarchicalGrid>
    

    Every IgbColumnGroup supports moving, pinning and hiding.

    [!Note] When there is a set of columns and column groups, pinning works only for top level column parents. More specifically pinning per nested column groups or columns is not allowed.
    Moving between columns and column groups is allowed only when they are at the same level in the hierarchy and both are in the same group.
    When columns/column-groups are not wrapped by current group which means they are top level columns, moving is allowed between whole visible columns.

    <IgbHierarchicalGrid Data="HierarchicalCustomers" Name="hierarchicalGrid" @ref="hierarchicalGrid" Id="hierarchicalGrid" PrimaryKey="ID" Moving="true" AllowFiltering="true">
        <IgbColumn Field="CustomerID" Sortable=true Resizable=true Movable=true DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumnGroup Movable=true Pinned="true" Header="General Information">
            <IgbColumn Field="CompanyName" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
            <IgbColumnGroup Movable=true Pinned="true" Header="General Information">
                <IgbColumn Field="ContactName" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="ContactTitle" Sortable=true Resizable=true DataType="GridColumnDataType.String"></IgbColumn>
            </IgbColumnGroup>
        </IgbColumnGroup>
    </IgbHierarchicalGrid>
    

    Multi-Column Header Template

    Each of the column groups of the grid can be templated separately. The column group expects RenderFragment for the HeaderTemplate property. The expression is provided with the column group object as a context.

    <IgbColumnGroup Header="Address Information" HeaderTemplate="Template">
    </IgbColumnGroup>
    
    @code {
        public RenderFragment<IgbColumnTemplateContext> Template = (ctx) => {
            string value = ctx.Column.Header.ToUpper();
            return @<span>@value</span>;
        };
    }
    

    Si quieres reutilizar una sola plantilla para varios grupos de columnas, podrías establecer laHeaderTemplate propiedad del grupo de columnas así:

    <IgbColumnGroup Header="General Information" HeaderTemplate="Template">
    </IgbColumnGroup>
    <IgbColumnGroup Header="Address Information" HeaderTemplate="Template">
    </IgbColumnGroup>
    
    @code {
        public RenderFragment<IgbColumnTemplateContext> Template = (ctx) => {
            string value = ctx.Column.Header.ToUpper();
            return @<span>@value</span>;
        };
    }
    

    [!Note] If a header is re-templated and the corresponding column group is movable, you have to set the draggable attribute to false on the templated elements, so that you can handle any of the events that are applied!

    @code {
        public Dictionary<string, object> DraggableAttributes { get; set; } =
            new Dictionary<string, object>()
            {
                { "draggable", "false" }
            };
    
        public RenderFragment<IgbColumnTemplateContext> Template = (ctx) => {
            return @<IgbIcon AdditionalAttributes="DraggableAttributes"  @onclick="onClick"/>;
        };
    }
    

    El siguiente ejemplo demuestra cómo implementar grupos de columnas contraíbles utilizando plantillas de encabezado.

    Styling

    Además de los temas predefinidos, la cuadrícula se puede personalizar aún más configurando algunas de las propiedades CSS disponibles. En caso de que desee cambiar algunos de los colores, primero debe establecer una clase para la cuadrícula:

    <IgbHierarchicalGrid class="grid"></IgbHierarchicalGrid>
    

    Luego establezca las propiedades CSS relacionadas con esta clase:

    .grid {
        --ig-grid-header-background: #e0f3ff;
        --ig-grid-header-text-color: #e41c77;
        --ig-grid-header-border-width: 1px;
        --ig-grid-header-border-style: solid;
        --ig-grid-header-border-color: rgba(0, 0, 0, 0.08);
    }
    

    Demo

    API References

    Additional Resources

    Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.