Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{first} in currentPageReportTemplate always resolves to "1" even when no rows match #9002

Closed
amithkk opened this issue Jul 3, 2020 · 8 comments
Assignees
Labels
LTS-FIXED-10.1.3 Fixed in PrimeNG LTS 10.1.3 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@amithkk
Copy link

amithkk commented Jul 3, 2020

I'm submitting a ...

[x] bug report 

Plunkr Case (Bug Reports)

Official Stackblitz for table component:
https://stackblitz.com/edit/primeng-tabledoc-demo

Current behavior
When there are no records loaded/no records matched on filtering, when using a template like "Showing {first} to {last} of {totalRecords} entries", {first} resolves to 1, leading to a rendered string "Showing 1 to 0 of 0 entries" which isn't technically correct

current behaviour

Expected behavior

When no suitable records are loaded, {first} resolves to 0 instead of 1, leading to the string "Showing 0 to 0 of 0 entries" which is accurate

Currently, a workaround to achieve this is to instead use your own template for the page report by using the paginatorright ng-template

Minimal reproduction of the problem with instructions

  1. Open the table-demo stackblitz: https://primeng-tabledoc-demo.stackblitz.io/
  2. Filter with a term that does not exist in the table

What is the motivation / use case for changing the behavior?
When there are no suitable records loaded into the table body, "0 to 0 of 0 records" is technically accurate

  • Angular version: 9.1.X
  • PrimeNG version: 9.1.0

  • Browser: all

  • Language: all

@pookdeveloper
Copy link

There's an other error, only replace the variables: {currentPage},{totalPages}

image

Thanks!

@yigitfindikli yigitfindikli added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Nov 23, 2020
@meta-vinod-sahu
Copy link

how to resolve this issue currently??

@tj-boyle
Copy link

tj-boyle commented Jan 5, 2021

This is an issue for our team as well.

@magemi
Copy link

magemi commented Jan 7, 2021

I created #9729 which should resolve this issue.

In the meantime, one workaround I was able to get to work is to use a ViewChild decorator and then manually manipulate the table's currentPageReportTable string in ngAfterViewInit():

<p-table #table currentPageReportTemplate="Showing {first} to {last} of {totalRecords} entries"></p-table>
export class TableComponent {
  @ViewChild("table") table: Table

  ngAfterViewInit(): void {
    if (this.table.totalRecords === 0) {
      this.table.currentPageReportTemplate = this.table.currentPageReportTemplate.replace("{first}", "0")
    }
  }
}

@meta-vinod-sahu
Copy link

ngAfterViewInit

according to your code suggestion this issue has not been resolved..when table has one row.According to your code it's showing 0 out of 1 of total record..in short your code has failed

@meta-vinod-sahu
Copy link

meta-vinod-sahu commented Jan 11, 2021 via email

@anuragsadhu
Copy link

  1. import - import { ChangeDetectorRef } from '@angular/core';
  2. update constructor - constructor(private cdRef: ChangeDetectorRef)
  3. use below code -

ngAfterViewChecked() {
if (this.table._totalRecords === 0) {
this.table.currentPageReportTemplate = this.table.currentPageReportTemplate.replace("{first}", "0")
} else {
this.table.currentPageReportTemplate = this.table.currentPageReportTemplate.replace("0", "{first}")
}
this.cdRef.detectChanges();
}

@meta-vinod-sahu
Copy link

meta-vinod-sahu commented Jan 15, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTS-FIXED-10.1.3 Fixed in PrimeNG LTS 10.1.3 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

7 participants