angular / angular/components

bug(cdk) Replacing datasource does not refresh/display items in cdk-virtual-scrollport

Abierto
#22,464 8 comentarios 7 reacciones 0 asignados Ver en GitHub
area: cdk/scrolling P3
Lenguaje dominante
TypeScript
Estrellas
25k
Forks
6.8k
Merge medio
1 d 8 h
PR fusionados (30 d)
91

Descripción

**Overview**

The first time you assign a datasource for iteration within the cdk-virtual-scrollport, all works as expected, as per the documentation example of displaying the first page of items. See "Virtual scroll with a custom data source" on https://material.angular.io/cdk/scrolling/examples

The bug however is if you subsequently try to assign a new instance of a datasource object to the same scroller. You will find that the scrollport will not request/display the first page of items from that new datasource **until the user scrolls the visible area**.

**Motivation/Use Case**
In the real-world our virtual data can require some sort of user driven filtering, like a search screen. Which will require a complete replacement of all the underlying/cached data in the scroller with fresh results. This is ideally achieved by replacing the datasource when the user triggers the search.

**Expected Behavior**
Scroller should reset itself automatically when given a new datasource and request the first page of rows in exactly the same way it does when it was assigned the first datasource.

**Actual Behavior**
CollectionViewer does not fire an event to the subscription in connect() until it has a range that differs.

**Minimal repro:**
See https://stackblitz.com/edit/angular-fs9xei-rgkahy?file=src%2Fapp%2Fcdk-virtual-scroll-data-source-example.ts

Run the sample, initial list items will appear. Click on the "Switch datasource button", and you will see the items in the list stuck with saying "loading..." indefinitely. You have to scroll before the datasource actually gets asked for data to be able to be displayed.

**Environment**
Angular: 11
CDK/Material: 11
Browser(s): n/a
Operating System (e.g. Windows, macOS, Ubuntu): n/a

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza ejecutando la reproducción enlazada de StackBlitz y revisando el ejemplo de data-source de CDK virtual scroll. Sigue cómo cdk-virtual-scrollport reemplaza su datasource y cómo los eventos de CollectionViewer llegan a la suscripción en connect(). Se considera terminado cuando cambiar las datasources solicita y muestra la primera página sin requerir desplazarse.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
angular, typescript
Área
frontend
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.