Ordenación de cuadrícula Angular
En Ignite UI for Angular Grid, la ordenación de datos está habilitada a nivel por columna, lo que significa que igx-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.
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 Grid Sorting Overview Example
This is done via the sortable input. With the 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.
IgxGrid proporciona una solución a 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 Grid API using the 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.grid.sort({ fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true });
// Perform sorting on both the ProductName and Price columns.
this.grid.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.grid.clearSort('ProductName');
// Removes the sorting state from every column in the Grid
this.grid.clearSort();
Note
The sortStrategy of the 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 Grid.
Initial sorting state
It is possible to set the initial sorting state of the Grid by passing an array of sorting expressions to the sortingExpressions property of the Grid.
public ngAfterViewInit(): void {
this.grid.sortingExpressions = [
{
dir: SortingDirection.Asc, fieldName: 'CategoryName',
ignoreCase: true, strategy: DefaultSortingStrategy.instance()
}
];
}
Note
If values of type string are used by a column of dataType Date, the Grid won't parse them to Date objects and using 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.
Remote Sorting
The Grid supports remote sorting, which is demonstrated in the Grid Remote Data Operations topic.
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-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
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
- 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