question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proper usage of datatable-pager

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[ X ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior The datatable-pager has been exported in #1046f84, so it would be good to show a demo on how to use it…

Actually if I have a template like this:

<ngx-datatable (page)="handlePageChange($event)">
  <ngx-datatable-footer>
    <ng-template 
      let-curPage="curPage" 
      let-offset="offset" 
      let-pageSize="pageSize" 
      let-rowCount="rowCount" 
      let-selectedCount="selectedCount" 
      ngx-datatable-footer-template>
    </ng-template>
    <datatable-pager 
      [count]="rowCount" 
      [page]="curPage" 
      [size]="pageSize" 
      (change)="handlePageChange($event)">
    </datatable-pager>
  </ngx-datatable-footer>
<ngx-datatable>

And in component:

handlePageChange (event: any): void {
  console.log(event); 
}

It prints only { page: x } instead of the whole object:

obj = {
  count: x, 
  pageSize: x, 
  limit: x, 
  offset: x
};

Expected behavior It must return the full object on datatable-pager.

Also, since it’s exported now, shouldn’t it be renamed to ngx-datatable-pager?

  • Table version: 9.1.0

  • Angular version: 4.0.3

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
Szabadembercommented, May 7, 2017

I created the pull request to export it, I only concentrated on the fact that this component is needed to make a proper custom footer 😃 .

I figured out how to use it by reading the source code. This is how I do it:

HTML:

<datatable-pager
    [pagerLeftArrowIcon]="'datatable-icon-left'"
    [pagerRightArrowIcon]="'datatable-icon-right'"
    [pagerPreviousIcon]="'datatable-icon-prev'"
    [pagerNextIcon]="'datatable-icon-skip'"
    [page]="curPage"
    [size]="pageSize"
    [count]="rowCount"
    [hidden]="!((rowCount / pageSize) > 1)"
    (change)="myTable.onFooterPage($event)">
</datatable-pager>

The change handler is really important to make paging work, you have to call the onFooter event handler of your ngx-datatable which I call myTable (Mark it as a child view #myTable).

I also think it would be a good idea to rename it.

11reactions
gyulauszkaicommented, Jun 8, 2017

Hi

I could not manage to make a custom footer with the pager. My code

<ngx-datatable
    class="material"
    [messages]="customMessages"
    [rows]="objectsToDisplay"
    [columnMode]="'flex'"
    [headerHeight]="50"
    [footerHeight]="150"
    [rowHeight]="50"
    [externalPaging]="true"
    [count]="page.totalElements"
    [offset]="page.pageNumber"
    [limit]="page.size"
    (page)='setPage($event)'
    [selectionType]="'single'"
    (select)="onSelect($event)"
  >
    <ngx-datatable-column [flexGrow]="1" prop="transactionNumber">
      <ng-template ngx-datatable-header-template>
        {{Number_Header}}
      </ng-template>
    </ngx-datatable-column>
 <ngx-datatable-footer>
      <ng-template
        ngx-datatable-footer-template
        let-rowCount="rowCount"
        let-pageSize="pageSize"
        let-selectedCount="selectedCount",
        let-curPage="curPage"
        let-offset="offset">
        <div style="padding: 5px 10px">
          <div>
            <strong>Summary</strong>: Gender: Female
          </div>
          <hr style="width:100%" />
          <div>
            Rows: {{rowCount}} |
            Size: {{pageSize}} |
            Current: {{curPage}} |
            Offset: {{offset}}
          </div>
        </div>
      </ng-template>
      <datatable-pager
        [pagerLeftArrowIcon]="'datatable-icon-left'"
        [pagerRightArrowIcon]="'datatable-icon-right'"
        [pagerPreviousIcon]="'datatable-icon-prev'"
        [pagerNextIcon]="'datatable-icon-skip'"
        [page]="curPage"
        [size]="pageSize"
        [count]="rowCount"
        [hidden]="!((rowCount / pageSize) > 1)"
        (change)="myTable.onFooterPage($event)">
      </datatable-pager>
    </ngx-datatable-footer>
  </ngx-datatable>

The custom footer shows but the pager is missing. Any ideas? Is there a working example somewhere?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alternative pagination - DataTables example
The default page control presented by DataTables (forward and backward buttons with up to 7 page numbers in-between) is fine for most situations,...
Read more >
Pagination using Datatables - GeeksforGeeks
In this article, we will learn to implement pagination using DataTables. Other features include sorting and multiple column ordering.
Read more >
Paging with Datatable - Webix
DataTable supports paging over the items in the data source. You enable and configure paging through the pager parameter. Paging doesn't depend on...
Read more >
How to add datatable pager template to Angular ngx datatable
According to "pager.component.ts" - you can't custom it ('datatable-pager' component). You may try to create your own one with the similar ...
Read more >
10. Add datatable in angular - YouTube
In this tutorial we will add datatable in list page, will add some packages, all the packages I will add below this section....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found