Angular Tree Grid Sorting
En Ignite UI for Angular Tree Grid, la ordenación de datos está habilitada a nivel de columna, lo que significa que igx-tree-grid puede tener una combinación de columnas ordenables y no ordenables. La realización de acciones de ordenación angular le permite cambiar el orden de visualización de los registros en función de los criterios especificados.
Nota
Hasta ahora, la agrupación/clasificación funcionaba en conjunto. En la versión 13.2, se introduce un nuevo comportamiento que desacopla la agrupación de la ordenación. Por ejemplo, al borrar la agrupación, no se borrarán las expresiones de ordenación en la cuadrícula o viceversa. Aun así, si una columna está ordenada y agrupada, las expresiones agrupadas tienen prioridad.
Ejemplo de descripción general de la clasificación de cuadrícula de árbol de Angular
Additionally there is a custom context menu added for sorting using igx-tree-grid's contextMenu Output.
This is done via the sortable input. With the Tree Grid sorting, you can also set the sortingIgnoreCase property to perform case sensitive sorting:
<igx-column field="Name" header="Order Product" [dataType]="'string'" sortable="true"></igx-column>
Indicadores de clasificación
Tener una cierta cantidad de columnas ordenadas puede resultar realmente confuso si no hay ninguna indicación del orden de clasificación.
IgxTreeGrid proporciona una solución a este problema indicando el índice de cada columna ordenada.
Ordenando a través de la API
You can sort any column or a combination of columns through the Tree Grid API using the Tree 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.treeGrid.sort({ fieldName: 'Name', dir: SortingDirection.Asc, ignoreCase: true });
// Perform sorting on both the ProductName and Price columns.
this.treeGrid.sort([
{ fieldName: 'Name', dir: SortingDirection.Asc, ignoreCase: true },
{ fieldName: 'UnitPrice', dir: SortingDirection.Desc }
]);
Nota
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.treeGrid.clearSort('Name');
// Removes the sorting state from every column in the Tree Grid
this.treeGrid.clearSort();
Nota
The sortStrategy of the Tree Grid is of different type compared to the sortStrategy of the column, since they work in different scopes and expose different parameters.
Nota
La operación de clasificación NO cambia la fuente de datos subyacente de Tree Grid.
Estado de clasificación inicial
It is possible to set the initial sorting state of the Tree Grid by passing an array of sorting expressions to the sortingExpressions property of the Tree Grid.
public ngAfterViewInit(): void {
this.treeGrid.sortingExpressions = [
{
dir: SortingDirection.Asc, fieldName: 'UnitPrice',
ignoreCase: true, strategy: DefaultSortingStrategy.instance()
}
];
}
Nota
If values of type string are used by a column of dataType Date, the Tree Grid won't parse them to Date objects and using Tree 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.
Plantillas de indicadores de clasificación
El icono del indicador de clasificación en el encabezado de la columna se puede personalizar mediante una plantilla. Las siguientes directivas están disponibles para crear plantillas del indicador de clasificación para cualquier estado de clasificación (ascendente, descendente, ninguno):
IgxSortHeaderIconDirective– re-templates the sorting icon when no sorting is applied.
<ng-template igxSortHeaderIcon>
<igx-icon>unfold_more</igx-icon>
</ng-template>
IgxSortAscendingHeaderIconDirective– re-templates the sorting icon when the column is sorted in ascending order.
<ng-template igxSortAscendingHeaderIcon>
<igx-icon>expand_less</igx-icon>
</ng-template>
IgxSortDescendningHeaderIconDirective– re-templates the sorting icon when the column is sorted in descending order.
<ng-template igxSortDescendingHeaderIcon>
<igx-icon>expand_more</igx-icon>
</ng-template>
Estilismo
To get started with styling the sorting behavior, we need to import the index file, where all the theme functions and component mixins live:
@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
);
Nota
Instead of hardcoding the color values like we just did, we can achieve greater flexibility in terms of colors by using the palette and color functions. Please refer to Palettes topic for detailed guidance on how to use them.
El último paso es incluir los mixins de componentes:
@include css-vars($custom-theme);
Manifestación
Nota
The sample will not be affected by the selected global theme from Change Theme.
Referencias de API
Recursos adicionales
- Descripción general de la cuadrícula de árbol
- Virtualización y rendimiento
- Paginación
- Filtración
- resúmenes
- Columna en movimiento
- Fijación de columnas
- Cambio de tamaño de columna
- Selección