ionic2 VirtualScroll does not redraw with empty list
Short description of the problem:
VirtualScroll does not redraw with empty list. When modifying the item list, it is rightly updating, but when the list becomes empty nothing happens.
What behavior are you expecting?
When the item list becomes empty, nothing should be visible anymore.
Steps to reproduce:
- Create a simple virtual scroll with an ion-list and ion-items
- Add some action or button that empties the list
- When that action triggers, nothing will happen
Which Ionic Version? 2.0.0-beta.6
Plunker that shows an example of your issue
http://plnkr.co/edit/xzwWnAtuzyQFkwQfrmAW?p=preview
Run ionic info from terminal/cmd prompt: (paste output below)
Your system information:
Cordova CLI: 6.0.0 Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.1 Ionic Framework Version: 2.0.0-beta.6 Ionic CLI Version: 2.0.0-beta.25 Ionic App Lib Version: 2.0.0-beta.15 OS: Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS Node Version: v6.1.0
I have also seen this when using a search box to filter a list. If there is a match to the search term the list correctly updates. If there is no match (ie empty list) nothing happens
Please fix this soon, this makes the virtualscroll list pretty unusable. I'm using a special "List empty" item as workaround by now, but that's not really nice.
You can still add an ngIf on that element for the moment, works like a charm 😉
@fdelayen @mpaland Could you kindly share your workarounds? where should I add the ngIf and what is the expression?
<ion-list [virtualScroll]="items">
<ion-item *virtualItem="#item" style="width:100%;">
Item {{item.title}}
</ion-item>
</ion-list>
I don't know if this issue has already been fixed in latest beta.10, but anyway:
<ion-list *ngIf="items.length > 0" [virtualScroll]="items">
<ion-item *virtualItem="let item" [style.width.%]="100">
Item {{item.title}}
</ion-item>
</ion-list>
@mpaland Thanks, I'm on beta 10 and still facing the issue. I tried the ngIf, didnt work for me. Probably because I'm using a pipe. ORIGINAL EXCEPTION: TypeError: Cannot read property 'length' of undefined
@WebEnzyme , if you're still having problems with the *ngIf you'll want to make sure that 'items' is being initialized.
i am also using *ngIf="items.length > 0" workaround for the same problem beta.11
I have tried using the *ngIf fix but when the list is shown again, the performance is terrible. The list has a terrible lag and is impossible to scroll on the device (testing on iOS)
Same for me in RC0. Work and list fill up but after update model to empty [] does not update list.
<ion-list *ngIf="showingSection == 'list'" [virtualScroll]="storesList?.items" approxItemHeight="70px">
<ion-item *virtualItem="let item" text-wrap>
Virtual Scroll component didn't get any love for a longer time. :-( Guess, ionic team has a focus on the final release, so this minor bug may get fixed later on...
Still an issue...
I have implemented this solution, until Ionic resolve the issue Always return a file with Id=0, after get the items do item.push('Id':0,etc.) if you have a filter add (actualcondition || item.Id==0) for always return this file In the label, button, input etc inside the ion-item *virtualitem, put [Hidden]="item.Id==0", this not affect the perfomance, not put in the ion-item *virtualitem this will affect the perfomance
Guys, to avoid the performance issue when using the *ngIf workaround, just replace it with a [hidden] attribute using the opposite logic. Example:
<ion-list [hidden]="items.length == 0">
Hope the Ionic team can soon fix this bug, though.
catched this issue just now in rc2
This Issue still exists in RC2
still having this problem in 2.8.0
still having also the same problem
@notsure @aarnaudiktons can you please fill a new issue? I can't reproduce this version in 2.2
@notsure ionic 2.8 does not exist
@manucorporat - This looks good for me in 2.2.0