swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

Incorrect behavior of rows @input with async pipe #1655

Closed andreyjkee closed 5 years ago

andreyjkee commented 5 years ago

I'm submitting a ... (check one with "x")

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

Current behavior When async pipe applied to rows input, table renders only last emitted data

Expected behavior Table should render all data emitted by observable

Reproduction of the problem

          this.displayedRows = Observable.create((subscriber) => {
            const dataRange = _.range(0, this.page.size, 10); // here 10 is a step
            dataRange.forEach((value, index, array) => {
              if (index !== array.length - 1) {
                subscriber.next(response.items.slice(value, array[index + 1]));
              } else {
                subscriber.next(response.items.slice(value, this.page.size));
              }
            });
            subscriber.complete();
          });

Template:

    <ngx-datatable
      class="material striped expandable"
      [columnMode]="'force'"
      [rows]="displayedRows | async"
      [headerHeight]="50"
      [footerHeight]="50"
      [rowHeight]="75"
      [columns]="columns"
      [sortType]="'multi'"
      [trackByProp]="'id'"
      [loadingIndicator]="isLoading"
      (sort)="onSort($event)"
      [externalPaging]="true"
      [externalSorting]="true"
      [count]="page.totalElements"
      [offset]="page.number"
      [limit]="page.size"
      (page)="setPage($event)">

Default page size is 50, when I receive 50 records from server, only latest 10 visible in table

eppsilon commented 5 years ago

The rows input expects to receive the entire set of rows to be shown in the table. If your observable is only emitting 10 at a time, it will only ever show 10.

If you want to show all rows emitted up until completion, you could use the reduce operator:

displayedRows.pipe(reduce((allRows, rows) => [...allRows, ...rows])
andreyjkee commented 5 years ago

@eppsilon thanks, so it was my incorrect usage of this feature, closing