Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
How to show pagination in thingsboard custom widget table?

I developed a widget where I display some data using the angular material table. The data is quite large and users need to scroll for a long time to see all the data. I want to show a pagination so that it will help users to see the data by clicking on the pagination link.

Here is my HTML code:

<mat-table [dataSource]="tableData" id="reportTable" style="background-color:inherit;">
    <ng-container *ngFor="let column of tableMeta" [matColumnDef]="column.key">
        <mat-header-cell *matHeaderCellDef [style.background-color]="settings?.tableHeaderBgColor" [style.color]="settings?.tableHeaderTxtColor">{{column.title}}
        </mat-header-cell>
        <mat-cell *matCellDef="let element" style="color:inherit;"> {{element[column.key]}} </mat-cell>
    </ng-container>
    <mat-header-row *matHeaderRowDef="displayedColumns" [style.background-color]="settings?.tableHeaderBgColor"></mat-header-row>
    <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>

Here is the JavaScript:

let $scope = self.ctx.$scope;
$scope.tableMeta=[{'title':'Date', 'key':'date'},{'title':'Online', 'key':'online'}, {'title':'Running', 'key': 'running'}, {'title':'Stopped', 'key': 'stopped'}, {'title':'Offline', 'key': 'offline'}];
$scope.displayedColumns=['date', 'online', 'running', 'stopped', 'offline'];
$scope.tableData=[] //Here will be the dataset.

Is there anyone who knows how to add functional pagination?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Something like this. Slice part of the data to dataSource and add the pagination element:

<mat-table
    [dataSource]="tableData.slice(tablePagination.getFrom(), tablePagination.getTo())"
    id="reportTable"
    style="background-color:inherit;"
>
    ...
    ...
</mat-table>
<mat-paginator
    [length]="tableData.length"
    [pageSize]="tablePagination.pageSize"
    [pageSizeOptions]="tablePagination.pageSizeOptions"
    (page)="tablePagination.handler($event)"
    aria-label="Select page"
    showFirstLastButtons="true"
></mat-paginator>

In your JS, set data, settings and the page handler:

self.onInit = () => {
    const tableData = [] // Your data
    const tablePagination = {
        pageIndex: 0,
        pageSize: 25,
        pageSizeOptions: [25, 50, 100],
        handler: (pagination) => {
            const { pageIndex, pageSize } = pagination;
            if (pageSize !== undefined) {
                tablePagination.pageSize = pageSize;
            }
            if (pageIndex !== undefined) {
                tablePagination.pageIndex = pageIndex;
            }
        },
        getFrom: () => {
            const { pageIndex, pageSize } = tablePagination;
            return pageIndex * pageSize;
        },
        getTo: () => {
            const { pageIndex, pageSize } = tablePagination;
            return pageIndex * pageSize + pageSize;
        }
    }

    const { $scope } = self.ctx
    $scope.tableData = tableData
    $scope.tablePagination = tablePagination
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda