Angular Classificação hierárquica em grade

    No Ignite UI for Angular Hierarchical Grid, a classificação de dados é habilitada em um nível por coluna, o que significa que a igx-hierarchical-grid pode ter uma combinação de colunas classificáveis e não classificáveis. A execução de ações de classificação angular permite alterar a ordem de exibição dos registros com base em critérios especificados.

    Note

    Até agora, o agrupamento/classificação funcionava em conjunto. Na versão 13.2, é introduzido um novo comportamento que separa o agrupamento da classificação. Por exemplo - limpar o agrupamento não limpará as expressões de classificação na grade ou vice-versa. Ainda assim, se uma coluna for classificada e agrupada, as expressões agrupadas terão precedência.

    Angular Hierarchical Grid Sorting Overview Example

    Additionally there is a custom context menu added for sorting using igx-hierarchical-grid's contextMenu Output.

    This is done via the sortable input. With the Hierarchical Grid sorting, you can also set the sortingIgnoreCase property to perform case sensitive sorting:

    <igx-column field="ProductName" header="Product Name" [dataType]="'string'" sortable="true"></igx-column>
    

    Sorting Indicators

    Ter uma certa quantidade de colunas classificadas pode ser realmente confuso se não houver indicação da ordem classificada.

    O IgxHierarchicalGrid fornece uma solução para esse problema indicando o índice de cada coluna classificada.

    Sorting through the API

    You can sort any column or a combination of columns through the Hierarchical Grid API using the Hierarchical Grid sort method:

    import { SortingDirection } from 'igniteui-angular/grids/core';
    // import { SortingDirection } from '@infragistics/igniteui-angular'; for licensed package
    
    // Perform a case insensitive ascending sort on the ProductName column.
    this.hierarchicalGrid.sort({ fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true });
    
    // Perform sorting on both the ProductName and Price columns.
    this.hierarchicalGrid.sort([
        { fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true },
        { fieldName: 'Price', dir: SortingDirection.Desc }
    ]);
    
    Note

    Sorting is performed using our DefaultSortingStrategy algorithm. Any IgxColumnComponent or ISortingExpression can use a custom implementation of the ISortingStrategy as a substitute algorithm. This is useful when custom sorting needs to be defined for complex template columns, or image columns, for example.

    As with the filtering behavior, you can clear the sorting state by using the clearSort method:

    // Removes the sorting state from the ProductName column
    this.hierarchicalGrid.clearSort('ProductName');
    
    // Removes the sorting state from every column in the Hierarchical Grid
    this.hierarchicalGrid.clearSort();
    
    Note

    The sortStrategy of the Hierarchical Grid is of different type compared to the sortStrategy of the column, since they work in different scopes and expose different parameters.

    Note

    A operação de classificação NÃO altera a fonte de dados subjacente da Grade Hierárquica.

    Initial sorting state

    It is possible to set the initial sorting state of the Hierarchical Grid by passing an array of sorting expressions to the sortingExpressions property of the Hierarchical Grid.

    public ngOnInit(): void {
        this.hierarchicalGrid.sortingExpressions = [
            { 
                dir: SortingDirection.Asc, fieldName: 'Artist',
                ignoreCase: true, strategy: DefaultSortingStrategy.instance() 
            }
        ];
    }
    
    Note

    If values of type string are used by a column of dataType Date, the Hierarchical Grid won't parse them to Date objects and using Hierarchical Grid sorting won't work as expected. If you want to use string objects, additional logic should be implemented on an application level, in order to parse the values to Date objects.

    Sorting Indicators Templates

    O ícone do indicador de classificação no cabeçalho da coluna pode ser personalizado usando um modelo. As seguintes diretivas estão disponíveis para modelar o indicador de classificação para qualquer estado de classificação (crescente, decrescente, nenhum):

    • IgxSortHeaderIconDirective– re-modelar o ícone de ordenação quando nenhuma ordenação é aplicada.
    <ng-template igxSortHeaderIcon>
        <igx-icon>unfold_more</igx-icon>
    </ng-template>
    
    • IgxSortAscendingHeaderIconDirective– re-templatea o ícone de ordenação quando a coluna é ordenada em ordem crescente.
    <ng-template igxSortAscendingHeaderIcon>
        <igx-icon>expand_less</igx-icon>
    </ng-template>
    
    • IgxSortDescendningHeaderIconDirective– re-templatear o ícone de ordenação quando a coluna está ordenada em ordem decrescente.
    <ng-template igxSortDescendingHeaderIcon>
        <igx-icon>expand_more</igx-icon>
    </ng-template>
    

    Estilização

    Para começar a estilizar o comportamento de ordenação, precisamos importar oindex arquivo, onde todas as funções de tema e mixins de componentes estão ativados:

    @use "igniteui-angular/theming" as *;
    
    // IMPORTANT: Prior to Ignite UI for Angular version 13 use:
    // @import '~igniteui-angular/lib/core/styles/themes/index';
    

    Following the simplest approach, we create a new theme that extends the grid-theme and accepts the $sorted-header-icon-color and sortable-header-icon-hover-color parameters.

    $custom-theme: grid-theme(
      $sorted-header-icon-color: #ffb06a,
      $sortable-header-icon-hover-color: black
    );
    
    Note

    Em vez de codificar os valores de cor como acabamos de fazer, podemos alcançar maior flexibilidade em termos de cores usando aspalette funções e.color Por favor, consulte oPalettes tópico para orientações detalhadas sobre como usá-los.

    A última etapa é incluir os mixins de componentes:

    @include css-vars($custom-theme);
    

    Demo

    Note

    A amostra não será afetada pelo tema global selecionado deChange Theme.

    API References

    Additional Resources

    Nossa comunidade é ativa e sempre acolhedora para novas ideias.