Ordenación de cuadrícula jerárquica Angular
En Ignite UI for Angular cuadrícula jerárquica, la ordenación de datos está habilitada a nivel por columna, lo que significa que la cuadrícula jerárquica igx 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.
Note
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.
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
Tener una cierta cantidad de columnas ordenadas puede resultar realmente confuso si no hay ninguna indicación del orden de clasificación.
IgxHierarchicalGrid proporciona una solución para este problema indicando el índice de cada columna ordenada.
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
La operación de clasificación NO cambia la fuente de datos subyacente de la Cuadrícula Jerá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
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-plantar el icono de ordenación cuando no se aplica ninguna ordenación.
<ng-template igxSortHeaderIcon>
<igx-icon>unfold_more</igx-icon>
</ng-template>
IgxSortAscendingHeaderIconDirective– vuelve a plantar el icono de ordenación cuando la columna se ordena en orden ascendente.
<ng-template igxSortAscendingHeaderIcon>
<igx-icon>expand_less</igx-icon>
</ng-template>
IgxSortDescendningHeaderIconDirective– vuelve a plantar el icono de ordenación cuando la columna se ordena en orden descendente.
<ng-template igxSortDescendingHeaderIcon>
<igx-icon>expand_more</igx-icon>
</ng-template>
Estilismo
Para empezar a estilizar el comportamiento de ordenación, necesitamos importar elindex archivo, donde están todas las funciones de tema y los componentes mixin:
@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
En lugar de codificar los valores de color como acabamos de hacer, podemos lograr mayor flexibilidad en cuanto a colores usando laspalette funciones ycolor. Por favor, consulta elPalettes tema para obtener una guía detallada sobre cómo utilizarlos.
El último paso es incluir los mixins de componentes:
@include css-vars($custom-theme);
Demo
Note
La muestra no se verá afectada por el tema global seleccionado deChange Theme.
API References
Additional Resources
- Descripción general de la cuadrícula jerárquica
- 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