HealthCatalyst / Fabric.Cashmere

Health Catalyst’s comprehensive design system.
http://cashmere.healthcatalyst.net
Apache License 2.0
66 stars 76 forks source link

Paginators and table filters persist empty results #1214

Open jfrseeley opened 4 years ago

jfrseeley commented 4 years ago

When filtering on a table component with a paginator, those filters resulting in no rows cause future filters to also result in no rows.

Steps to reproduce:

  1. Assign a paginator (I used LoadMorePaginationComponent) to the data source.
  2. Apply a filter that excludes all rows.
  3. Clear filter to see that rows are not reinstated.

Workaround: Use the paginator to load more.

Stackblitz: https://stackblitz.com/edit/angular-ysxljy

Note: Stackblitz link is a fork of the Pagination Load More example, combined with snippets from the Table Filter example

PaginatorWithFilter

jfrseeley commented 4 years ago

FYI, this hack serves as a workaround:

const hadNoRows = this.dataSource.filteredData.length === 0;
this.dataSource.filter = filter.trim().toLowerCase();

const hasRows = this.dataSource.filteredData.length > 0;
if (hadNoRows && hasRows) {
  this.loadMoreBtn._loadNextPage();
}
jfrseeley commented 4 years ago

I've also found this bug applies if the table component's paginator field is set before loading any rows. Thus, it isn't exclusive to trying to combine filters and paginators. The paginator just doesn't seem to know how to respond when the table is moving from an empty row set to a non-empty row set.