Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ionic2 VirtualScroll does not redraw with empty list #6512

Closed
fdelayen opened this issue May 12, 2016 · 36 comments
Closed

ionic2 VirtualScroll does not redraw with empty list #6512

fdelayen opened this issue May 12, 2016 · 36 comments
Assignees
Milestone

Comments

@fdelayen
Copy link

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 fdelayen changed the title VirtualScroll does not redraw with empty list ionic2 VirtualScroll does not redraw with empty list May 12, 2016
@jgw96 jgw96 added the v2 label May 12, 2016
@ghenry22
Copy link

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

@mpaland
Copy link

mpaland commented Jun 8, 2016

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.

@fdelayen
Copy link
Author

fdelayen commented Jun 8, 2016

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

@WebEnzyme
Copy link

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

@mpaland
Copy link

mpaland commented Jul 21, 2016

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>

@WebEnzyme
Copy link

WebEnzyme commented Jul 21, 2016

@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

@jarrodkoch
Copy link

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

@comfortme
Copy link

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

@mbrookson
Copy link

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)

@jafaripur
Copy link

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>

@mpaland
Copy link

mpaland commented Oct 3, 2016

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

@zakton5
Copy link
Contributor

zakton5 commented Oct 25, 2016

Still an issue...

@aarnaudiktons
Copy link

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

@AbrahamLopez10
Copy link

AbrahamLopez10 commented Nov 6, 2016

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.

@pavimus
Copy link

pavimus commented Nov 7, 2016

catched this issue just now in rc2

@OmarHassan25
Copy link

This Issue still exists in RC2

@adamdbradley adamdbradley added this to the 2.0.0-rc.4 milestone Nov 20, 2016
@notsure
Copy link

notsure commented Mar 13, 2017

still having this problem in 2.8.0

@aarnaudiktons
Copy link

still having also the same problem

@manucorporat
Copy link
Contributor

@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

@ghenry22
Copy link

@manucorporat - This looks good for me in 2.2.0

@dspachos
Copy link

Still have the issue, when list is empty.
Quick and dirty solution, push something e.g.

if(this.speakers.length==0) { 
                    this.speakers.push( {'none':1} );
                  }

and then check it, e.g.
<ion-card class="speaker-card" *ngIf="speaker.none==null">

I implemented a filter in authors tab in the Conference app example this way, works fine

@parkbroom
Copy link

@dspachos how did you use this with virtualscroll? mind showing me the full html?

@dspachos
Copy link

Here you are:

<ion-content class="outer-content speaker-list">
  <ion-list [virtualScroll]="speakers">
    <ion-grid fixed>
      <ion-row align-items-stretch>

        <ion-col col-12 col-md-6 align-self-stretch align-self-center *virtualItem="let speaker" approxItemHeight="457px">

          <ion-card class="speaker-card" *ngIf="speaker.none==null">
            <ion-card-header>
..

hope it helps!

@Tankatronic
Copy link

Any updates on this issue? I am also experiencing it.

@zakton5
Copy link
Contributor

zakton5 commented Jul 20, 2017

Still experiencing this problem

@dzmitrys-dev
Copy link

Still reproduced

@dzmitrys-dev
Copy link

Please reopen

@Ross-Rawlins
Copy link

This is still an issue

@decpio
Copy link

decpio commented Aug 17, 2017

ionic 3.6 and still same problem.
I use
[hidden]="(__items?.length || 0) == 0"
to resolve empty list and null either

@aminkor
Copy link

aminkor commented Sep 20, 2017

solved it using this answer. https://stackoverflow.com/a/44041426

@savs90
Copy link

savs90 commented Oct 25, 2017

ionic 3.7.1 and still the same problem

@demym
Copy link

demym commented Jan 2, 2018

Some news about the virtualscroll issues ? I'm on 3.10.3 and still virtualscroll not working correctly; well, sometimes it does, but have issues as:

  • refresh items array --> sometimes i get a blank view...
  • overlapping items (i'm using it in a chat page which has some differences in items height); this happens only from time to time...

Very sorry as virtualscroll is really a plus and helps get performances at the top, but the random issues stop me to use it in production

@442623641
Copy link

fixed:
@ViewChild('virtualScroll', { read: VirtualScroll }) virtualScroll: VirtualScroll;

setTimeout(() => {
                this.virtualScroll['_ctrl'].readReady.emit();
                setTimeout(() => this.virtualScroll['_ctrl'].writeReady.emit(), 300);
            }, 300)

@lordgreg
Copy link

lordgreg commented Feb 9, 2018

@442623641 so to understand the "fix":

Every 300ms we send an READY event for virtualscroll and after 300ms after submitting an event, we send writeReady event.

What that basically means is, that VirtualScroll redraws every 300ms?

@jgpATs2w
Copy link

jgpATs2w commented Feb 23, 2018

My solution came using the renderVirtual method of VirtualScroll directive. In my case the 'white issue' came when the input array of virtualscroll

pages/mypage/mypage.hml
<ion-list #virtualScroll [virtualScroll]="myarray"

pages/mypage/mypage.ts

 import { ViewChild } from '@angular/core';
 import { VirtualScroll } from 'ionic-angular';
 ...
export class MyPage {
  @ViewChild('virtualScroll', { read: VirtualScroll }) virtualScroll: VirtualScroll;
   ...
    ionViewWillEnter(){
        // code that updates data inside myarray
        this.virtualScroll.renderVirtual(true);
    }

There is also writeUpdate method, that performs some extra calculations. Someone knows which is better?

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 1, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests