angular paginator set item for pages like 50 but list is empty

84 Views Asked by At

I use paginator in a search page. The paginator works fine untils the list are not empty.

<mat-paginator [length]="numbersTotalElements" [pageSize]="numberRowForPage" [pageIndex]="first" aria-label="Seleziona pagina" tabindex="0"> </mat-paginator>

I call a subscrive and I do this:

   this.searchStudentService.search(this.fieldsSearch).pipe(takeUntil(this.subscrive$)).subscribe((result) => {
        if (Utility.isNotNull(resultResponse)) {

          
          this.listSearch = Utility.extractList(resultResponse);

          this.numbersTotalElements= SortUtility.extract-...(resultResponse);
          this.numberRowForPage= SortUtility.extract...(resultResponse);
        
          this.first = 0;
          console.log(this.numbersTotalElements)
          console.log(this.numberRowForPage)
          console.log(this.first)
          this.dataSource = new MatTableDataSource<SearchResultStudent>(this.listSearch );

The problem is tha code work fine when I have (from my respose) some values but when the response is empty I read this: enter image description here

the "elements for page is 50 but the console.log it prints me all 0 so I don't know it take this 50.Anyne can help me?

1

There are 1 best solutions below

0
On

This 50 belongs to numberRowForPage. It indicates the number of element that the page could show. If you return 0 elements, you should set numberRowForPage also to 0.