React Tree Grid Sorting
The Ignite UI for React Data Sorting feature in React Tree Grid is enabled on a per-column level, meaning that the IgrTreeGrid can have a mix of sortable and non-sortable columns. Performing React sort actions enables you to change the display order of the records based on specified criteria.
React Tree Grid Sorting Overview Example
Esto se hace mediante lasortable entrada. Con laIgrTreeGrid ordenación, también puedes configurar lasortingIgnoreCase propiedad para realizar ordenación con distinción de mayúsculas y minúsculas:
<IgrColumn field="ProductName" header="Product Name" dataType="string" sortable={true}></IgrColumn>
Sorting Indicators
Tener una cierta cantidad de columnas ordenadas puede resultar realmente confuso si no hay ninguna indicación del orden de clasificación.
ProporcionaIgrTreeGrid una solución a este problema indicando el índice de cada columna ordenada.
Sorting through the API
Puedes ordenar cualquier columna o una combinación de columnas a través de laIgrTreeGrid API usando laIgrTreeGrid sort Método:
import { SortingDirection } from "igniteui-react-grids";
// Perform a case insensitive ascending sort on the Category column.
treeGridRef.current.sort([{ fieldName: 'Category', dir: SortingDirection.Asc, ignoreCase: true }]);
// Perform sorting on both the Category and Price columns.
treeGridRef.current.sort([
{ fieldName: 'Category', dir: SortingDirection.Asc, ignoreCase: true },
{ fieldName: 'Price', dir: SortingDirection.Desc }
]);
[!Note] Sorting is performed using our
DefaultSortingStrategyalgorithm. AnyIgrColumnorISortingExpressioncan use a custom implementation of theISortingStrategyas a substitute algorithm. This is useful when custom sorting needs to be defined for complex template columns, or image columns, for example.
Al igual que con el comportamiento de filtrado, puedes borrar el estado de ordenación usando elclearSort método:
// Removes the sorting state from the Category column
treeGridRef.current.clearSort('Category');
// Removes the sorting state from every column in the Tree Grid
treeGridRef.current.clearSort();
[!Note] The
sortStrategyof theIgrTreeGridis of different type compared to thesortStrategyof theIgrColumn, since they work in different scopes and expose different parameters.
[!Note] The sorting operation DOES NOT change the underlying data source of the
IgrTreeGrid.
Initial Sorting State
Es posible establecer el estado inicial de ordenamiento de pasandoIgrTreeGrid un array de expresiones de ordenación a lasortingExpressions propiedad de laIgrTreeGrid.
const sortingExpressions: IgrSortingExpression[] = [
{ fieldName: 'Category', dir: SortingDirection.Asc, ignoreCase: true },
{ fieldName: 'Price', dir: SortingDirection.Desc }
];
<IgrTreeGrid
data={productSales}
sortingExpressions={sortingExpressions}>
</IgrTreeGrid>
[!Note] If values of type
stringare used by a column ofdataTypeDate, theIgrTreeGridwon't parse them toDateobjects and usingIgrTreeGridSortingwon't work as expected. If you want to usestringobjects, additional logic should be implemented on an application level, in order to parse the values toDateobjects.
Sorting Indicators Templates
El icono del indicador de clasificación en el encabezado de la columna se puede personalizar mediante una plantilla. Las siguientes propiedades están disponibles para crear plantillas del indicador de clasificación para cualquier estado de clasificación (ascendente, descendente, ninguno):
sortHeaderIconTemplate– re-plantar el icono de ordenación cuando no se aplica ninguna ordenación.
const sortHeaderIconTemplate = (ctx: IgrGridHeaderTemplateContext) => {
return (
<>
<IgrIcon name='unfold_more'></IgrIcon>
</>
);
}
<IgrTreeGrid sortHeaderIconTemplate={sortHeaderIconTemplate}></IgrTreeGrid>
sortAscendingHeaderIconTemplate– vuelve a plantar el icono de ordenación cuando la columna se ordena en orden ascendente.
const sortAscendingHeaderIconTemplate = (ctx: IgrGridHeaderTemplateContext) => {
return (
<>
<IgrIcon name='expand_less'></IgrIcon>
</>
);
}
<IgrTreeGrid sortAscendingHeaderIconTemplate={sortAscendingHeaderIconTemplate}></IgrTreeGrid>
sortDescendingHeaderIconTemplate– vuelve a plantar el icono de ordenación cuando la columna se ordena en orden descendente.
const sortDescendingHeaderIconTemplate = (ctx: IgrGridHeaderTemplateContext) => {
return (
<>
<IgrIcon name='expand_more'></IgrIcon>
</>
);
}
<IgrTreeGrid sortDescendingHeaderIconTemplate={sortDescendingHeaderIconTemplate}></IgrTreeGrid>
Styling
Además de los temas predefinidos, la cuadrícula se puede personalizar aún más configurando algunas de las propiedades CSS disponibles. En caso de que desee cambiar algunos de los colores, primero debe establecer una clase para la cuadrícula:
<IgrTreeGrid className="grid">
</IgrTreeGrid>
Luego establezca las propiedades CSS relacionadas con esta clase:
.grid {
--ig-grid-sorted-header-icon-color: #ffb06a;
--ig-grid-sortable-header-icon-hover-color: black;
}
Demo
API References
Additional Resources
Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.