Visão geral dos cabeçalhos de várias colunas da grade de Web Components

    The Ignite UI for Web Components Multi-Column Headers feature in Web Components Grid allows you to group columns by placing them under a common multi-header. Each multi-column headers group in the IgcGridComponent 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.

    Web Components Grid Multi-Column Headers Example

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

    <igc-grid allow-filtering="true">
        <igc-column-group header="Contact Information">
            <igc-column sortable="true" resizable="true" field="Phone"></igc-column>
            <igc-column sortable="true" resizable="true" field="Fax"></igc-column>
            <igc-column sortable="true" resizable="true" field="PostalCode"></igc-column>
        </igc-column-group>
    </igc-grid>
    

    Para alcançarn-th o nível de cabeçalhos aninhados, a declaração acima deve ser seguida. Então, ao aninharcolumnGroup leva ao resultado desejado.

    <igc-grid height="600px" allow-filtering="true">
        <igc-column-group header="General Information">
            <igc-column movable="true" sortable="true" resizable="true" field="CompanyName"></igc-column>
            <igc-column-group movable="true" header="Person Details">
                <igc-column movable="true" pinned="false" sortable="true" resizable="true" field="ContactName"></igc-column>
                <igc-column movable="true" sortable="true" resizable="true" field="ContactTitle"></igc-column>
            </igc-column-group>
        </igc-column-group>
    </igc-grid>
    

    Every columnGroup 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.

    <igc-grid height="600px" allow-filtering="true">
        <igc-column-group  movable="true" pinned="true" header="General Information">
            <igc-column movable="true" sortable="true" resizable="true" field="CompanyName"></igc-column>
        </igc-column-group>
        <igc-column sortable="true" resizable="true" field="Phone"></igc-column>
        <igc-column sortable="true" resizable="true" field="Fax"></igc-column>
        <igc-column sortable="true" resizable="true" field="PostalCode"></igc-column>
    </igc-grid>
    

    Multi-Column Header Template

    Each of the column groups of the grid can be templated separately. The following code snippet demonstrates how to use the headerTemplate of a column group:

    <igc-column-group id="addressInfo" header="Address Information">
    </igc-column-group>
    
    constructor() {
        var addresss = this.addresss = document.getElementById('addressInfo') as IgcColumnGroupComponent;
        addresss.headerTemplate = this.columnGroupHeaderTemplate;
    }
    
    public columnGroupHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
        return html`
            ${ctx.column.header.toUpperCase()}
        `;
    }
    

    Se você quiser reutilizar um único modelo para vários grupos de colunas, pode definir aheaderTemplate propriedade do grupo de colunas assim:

    <igc-column-group id="generalInfo" header="General Information">
    </igc-column-group>
    <igc-column-group id="addressInfo" header="Address Information">
    </igc-column-group>
    
    constructor() {
        var general = this.general = document.getElementById('generalInfo') as IgcColumnGroupComponent;
        var addresss = this.address = document.getElementById('addressInfo') as IgcColumnGroupComponent;
        general.headerTemplate = this.columnGroupHeaderTemplate;
        addresss.headerTemplate = this.columnGroupHeaderTemplate;
    }
    
    public columnGroupHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
        return html`
            ${ctx.column.header.toUpperCase()}
        `;
    }
    

    [!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!

    public columnHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
        return html`
            <igc-icon draggable="false" @click="${() => this.onClick()}"></igc-icon>
        `;
    }
    

    O exemplo a seguir demonstra como implementar grupos de colunas recolhíveis usando modelos de cabeçalho.

    Styling

    Além dos temas predefinidos, a grade pode ser ainda mais personalizada ao definir algumas das propriedades CSS disponíveis. Caso você queira alterar algumas das cores, precisa definir uma classe para a grade primeiro:

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

    Em seguida, defina as propriedades CSS relacionadas a esta classe:

    .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

    Nossa comunidade é ativa e sempre acolhedora para novas ideias.