Angular Tree Grid Pagination

    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. Tree 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 Material table, the pagination in the Tree Grid supports template for custom pages.

    Angular Pagination Example

    The following example represents Tree 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 Tree 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 Tree Grid to enable paging:

    <igx-tree-grid #treeGrid [data]="data" [height]="'500px'" [width]="'100%'" [displayDensity]="'cosy'">
        <igx-paginator [perPage]="10">
        </igx-paginator>
    </igx-tree-grid>
    

    Example:

    <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-tree-grid component in the example below, but you can use it with any other component in case paging functionality is needed.

    <igx-tree-grid #treeGrid [data]="data">
        <igx-paginator #paginator [(page)]="treeGrid.page" [totalRecords]="treeGrid.length" [(perPage)]="10"
                [selectOptions]="selectOptions" [displayDensity]="treeGrid.displayDensity">
        </igx-paginator>
    </igx-tree-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 Tree Grid Remote Data Operations topic.

    Pagination Styling in Angular

    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';
    

    Following the simplest approach, we create a new theme that extends the igx-paginator-theme and accepts the $text-color, $background-color and the $border-color parameters.

    $dark-paginator: igx-paginator-theme(
        $text-color: #F4D45C,
        $background-color: #575757,
        $border-color: #292826
    );
    

    As seen, the igx-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 button theme:

    $dark-button: igx-button-theme(
        $icon-color: #FFCD0F,
        $icon-hover-color: #292826,
        $icon-hover-background: #FFCD0F,
        $icon-focus-color: #292826,
        $icon-focus-background: #FFCD0F,
        $disabled-color: #16130C
    );
    

    In this example we only changed the icon color and background and the button disabled color, but the the igx-button-theme provides way more parameters to control the button style.

    The last step is to include the component mixins, each with its respective theme:

    @include igx-grid-paginator($dark-grid-paginator);
    .igx-grid-paginator__pager {
        @include igx-button($dark-button);
    }
    
    Note

    We scope the igx-button mixin within .igx-paginator__pager, so that only the paginator buttons would be styled. Otherwise other 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:

    :host {
        ::ng-deep {
            @include igx-paginator($dark-paginator);
            .igx-paginator__pager {
                @include igx-button($dark-button);
            }
        }
    }
    

    Defining a Color Palette

    Instead of hardcoding the color values like we just did, we can achieve greater flexibility in terms of colors by using the igx-palette and igx-color functions.

    igx-palette generates a color palette based on the primary and secondary colors that are passed:

    $yellow-color: #F9D342;
    $black-color: #292826;
    
    $dark-palette: igx-palette($primary: $black-color, $secondary: $yellow-color);
    

    And then with igx-color we can easily retrieve color from the pallette.

    $dark-paginator: igx-paginator-theme(
        $palette: $dark-palette,
        $text-color: igx-color($dark-palette, "secondary", 400),
        $background-color: igx-color($dark-palette, "primary", 200),
        $border-color:  igx-color($dark-palette, "primary", 500)
    );
    
    $dark-button: igx-button-theme(
        $palette: $dark-palette,
        $icon-color: igx-color($dark-palette, "secondary", 700),
        $icon-hover-color: igx-color($dark-palette, "primary", 500),
        $icon-hover-background: igx-color($dark-palette, "secondary", 500),
        $icon-focus-color: igx-color($dark-palette, "primary", 500),
        $icon-focus-background: igx-color($dark-palette, "secondary", 500),
        $disabled-color: igx-color($dark-palette, "primary", 700)
    );
    
    Note

    The igx-color and igx-palette are powerful functions for generating and retrieving colors. Please refer to Palettes topic for detailed guidance on how to use them.

    Using Schemas

    Going further with the theming engine, you can build a robust and flexible structure that benefits from schemas. A schema is a recipe of a theme.

    Extend one of the two predefined schemas, that are provided for every component, in this case - dark-pagination and dark-button schemas:

    // Extending the dark paginator schema
    $dark-paginator-schema: extend($_dark-pagination,
            (
                text-color:(
                    igx-color: ("secondary", 400)
                ),
                background-color:(
                    igx-color: ("primary", 200)
                ),
                border-color:(
                    igx-color:( "primary", 500)
                )
            )
    );
    // Extending the dark button schema
    $dark-button-schema: extend($_dark-button,
            (
                icon-color:(
                    igx-color:("secondary", 700)
                ),
                icon-hover-color:(
                    igx-color:("primary", 500)
                ),
                icon-hover-background:(
                    igx-color:("secondary", 500)
                ),
                icon-focus-color:(
                    igx-color:("primary", 500)
                ),
                icon-focus-background:(
                    igx-color:("secondary", 500)
                ),
                disabled-color:(
                    igx-color:("primary", 700)
                )
            )
    );
    

    In order to apply our custom schemas we have to extend one of the globals (light or dark), which is basically pointing out the components with a custom schema, and after that add it to the respective component themes:

    // Extending the global dark-schema
    $custom-dark-schema: extend($dark-schema,(
        igx-paginator: $dark-paginator-schema,
        igx-button: $dark-button-schema
    ));
    
    // Defining igx-paginator-theme with the global dark schema
    $dark-paginator: igx-paginator-theme(
      $palette: $dark-palette,
      $schema: $custom-dark-schema
    );
    
    // Defining button-theme with the global dark schema
    $dark-button: igx-button-theme(
      $palette: $dark-palette,
      $schema: $custom-dark-schema
    );
    

    Don't forget to include the themes in the same way as it was demonstrated above.

    Demo

    API References

    Additional Resources

    Our community is active and always welcoming to new ideas.