ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

ionic2 VirtualScroll does not redraw with empty list

Open fdelayen opened this issue 10 years ago • 36 comments

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:

  1. Create a simple virtual scroll with an ion-list and ion-items
  2. Add some action or button that empties the list
  3. 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

fdelayen avatar May 12 '16 12:05 fdelayen

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

ghenry22 avatar May 25 '16 22:05 ghenry22

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.

mpaland avatar Jun 08 '16 12:06 mpaland

You can still add an ngIf on that element for the moment, works like a charm 😉

fdelayen avatar Jun 08 '16 18:06 fdelayen

@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>

WebEnzyme avatar Jul 21 '16 12:07 WebEnzyme

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 avatar Jul 21 '16 12:07 mpaland

@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 avatar Jul 21 '16 13:07 WebEnzyme

@WebEnzyme , if you're still having problems with the *ngIf you'll want to make sure that 'items' is being initialized.

jarrodkoch avatar Jul 29 '16 15:07 jarrodkoch

i am also using *ngIf="items.length > 0" workaround for the same problem beta.11

comfortme avatar Aug 21 '16 07:08 comfortme

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)

mbrookson avatar Sep 07 '16 08:09 mbrookson

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>

jafaripur avatar Oct 02 '16 06:10 jafaripur

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...

mpaland avatar Oct 03 '16 09:10 mpaland

Still an issue...

zakton5 avatar Oct 25 '16 14:10 zakton5

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

aarnaudiktons avatar Oct 31 '16 05:10 aarnaudiktons

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.

AbrahamLopez10 avatar Nov 06 '16 09:11 AbrahamLopez10

catched this issue just now in rc2

pavimus avatar Nov 07 '16 19:11 pavimus

This Issue still exists in RC2

OmarHassan25 avatar Nov 13 '16 13:11 OmarHassan25

still having this problem in 2.8.0

notsure avatar Mar 13 '17 11:03 notsure

still having also the same problem

aarnaudiktons avatar Mar 13 '17 11:03 aarnaudiktons

@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 avatar Mar 14 '17 22:03 manucorporat

@manucorporat - This looks good for me in 2.2.0

ghenry22 avatar Mar 15 '17 02:03 ghenry22