Paginación de cuadrícula jerárquica Angular
Pagination is used to split a large set of data into a sequence of pages that have similar content. Angular table pagination improves user experience and data interaction. Hierarchical Grid pagination is configurable via a separate component projected in the grid tree by defining a igx-paginator tag, similar to adding of a column. As in any Angular Table, the pagination in the Hierarchical Grid supports template for custom pages.
Angular Pagination Example
The following example represents Hierarchical Grid pagination and exposes the options usage of items per page and how paging can be enabled. The user can also quickly navigate through the Hierarchical Grid pages via "Go to last page" and "Go to first page" buttons.
Adding a igx-paginator component will control whether the feature is present, you can enable/disable it by using a simple *ngIf with a toggle property. The perPage input controls the visible records per page. Let’s update our Hierarchical Grid to enable paging:
<igx-hierarchical-grid #hierarchicalGrid [data]="data" [height]="'500px'" [width]="'100%'">
<igx-paginator [perPage]="10">
</igx-paginator>
</igx-hierarchical-grid>
Ejemplo:
<igx-paginator #paginator [totalRecords]="20">
<igx-paginator-content>
<div id="numberPager" style="justify-content: center;">
<button [disabled]="paginator.isFirstPage" (click)="paginator.previousPage()" igxButton="flat">
PREV
</button>
<span>
Page {{paginator.page}} of {{paginator.totalPages}}
</span>
<button [disabled]="paginator.isLastPage" (click)="paginator.nextPage()" igxButton="flat">
NEXT
</button>
</div>
</igx-paginator-content>
</igx-paginator>
Usage
The igx-paginator component is used along with the igx-hierarchical-grid component in the example below, but you can use it with any other component in case paging functionality is needed.
<igx-hierarchical-grid>
<igx-column *ngFor="let c of hColumns" [field]="c.field">
</igx-column>
<igx-row-island [key]="'childData'" [autoGenerate]="true">
<igx-row-island [key]="'childData'" [autoGenerate]="true">
<igx-paginator *igxPaginator></igx-paginator>
</igx-row-island>
<igx-paginator *igxPaginator></igx-paginator>
</igx-row-island>
<igx-row-island [key]="'childData2'" [autoGenerate]="true">
<igx-paginator *igxPaginator></igx-paginator>
</igx-row-island>
<igx-paginator></igx-paginator>
</igx-hierarchical-grid>
Paginator Configuration within child grids
Debido a ciertas limitaciones en cómo se implementan las cuadrículas secundarias de IgxHierarchicalGrid y cómo funciona el alcance DI, al definir un componente de paginador dentro de las etiquetas igx-row-island, siempre asegúrese de usar la directiva IgxPaginator en el paginador mismo. Esto asegurará que la cuadrícula secundaria tenga la instancia del paginador correcta como referencia:
<igx-hierarchical-grid>
...
<igx-row-island>
...
<igx-grid-toolbar *igxPaginator>
...
</igx-grid-toolbar>
</igx-row-island>
...
</igx-hierarchical-grid>
Paginator Component Demo
Remote Paging
Remote paging can be achieved by declaring a service, responsible for data fetching and a component, which will be responsible for the Grid construction and data subscription. For more detailed information, check the Hierarchical Grid Remote Data Operations topic.
Estilismo
To get started with styling the paginator, 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';
Siguiendo el enfoque más sencillo, creamos un nuevo tema que extiende lospaginator-theme y acepta los$text-color$background-color$border-color parámetros.
$dark-paginator: paginator-theme(
$text-color: #d0ab23;,
$background-color: #231c2c,
$border-color: #d0ab23;
);
As seen, the paginator-theme only controls colors for the paging container, but does not affect the buttons in the pager UI. To style those buttons, let's create a new icon button theme:
$dark-button: icon-button-theme(
$foreground: #d0ab23,
$hover-foreground: #231c2c,
$hover-background: #d0ab23,
$focus-foreground: #231c2c,
$focus-background: #d0ab23,
$disabled-foreground: #9b7829
);
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, cada uno con su respectiva temática:
@include css-vars($dark-paginator);
.igx-grid-paginator__pager {
@include css-vars($dark-button);
}
Note
We include the created icon-button-theme within .igx-paginator__pager, so that only the paginator buttons would be styled. Otherwise other icon buttons in the grid would be affected too.
Note
If the component is using an Emulated ViewEncapsulation, it is necessary to penetrate this encapsulation using ::ng-deep in order to style the components which are inside the paging container, like the button:
@include css-vars($dark-paginator);
:host {
igx-paginator {
::ng-deep {
@include css-vars($dark-button);
}
}
}
Demo
API References
Additional Resources
- Descripción general de la cuadrícula jerárquica
- Paginador
- Virtualización y rendimiento
- Filtración
- Clasificación
- resúmenes
- Columna en movimiento
- Fijación de columnas
- Cambio de tamaño de columna
- Selección