dinony / od-virtualscroll

🚀 Observable-based virtual scroll implementation in Angular
https://dinony.github.io/od-vsstatic/
MIT License
134 stars 12 forks source link

Prefered way to force redraw of rows/items. #10

Open ktersius opened 7 years ago

ktersius commented 7 years ago

Currently when options like item sizes are changed I have to somehow force the component to redraw. It seems that emitting the options itself is not enough to trigger any sort of redraw.

If I only emit options they seem to only take effect as I scroll through the items and the rows are updated.

For now I'm emitting an empty array and then right after that the data array, this seems to make it redraw but it feels messy.

 subs.push(this.debounceResize$.subscribe(() => {
        observer.next([]);
        observer.next(curData);
      }));
dinony commented 7 years ago

Hi @ktersius, yeah, this is an issue I am aware of and I will look into it. The reason I did not implement it in the first place is that I was unsure, whether it could harm the performance or not. But as there seems to be a use case, I will evaluate the practicability. Thanks!

musicq commented 6 years ago

Yup, I met the same problem today, but I solved it by this tricky way.

In templates

<od-virtualscroll [vsData]="data$" [vsOptions]="options$">
...
</od-virtualscroll>

In components

data$ = new Subject<number[]>();

change() {
    // use this to force redraw
    this.data$.next([]);
    this.data$.next(new Array(100).fill(0).map(x => Math.floor(Math.random() * 1000)));
}
dinony commented 6 years ago

Yeah thanks. But it's still something, which needs to be addressed in future. I hope I will find some time for another maintenance/feature request round.

furlongce commented 6 years ago

Have you had a chance to look into this? I'm facing a similar issue.

dinony commented 6 years ago

Not yet, but I (or someone else :+1:) will!