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

Performance: Drop down opening slow when repeated in NgFor #900

Closed
brandoncollins opened this issue Oct 17, 2016 · 29 comments
Closed

Performance: Drop down opening slow when repeated in NgFor #900

brandoncollins opened this issue Oct 17, 2016 · 29 comments

Comments

@brandoncollins
Copy link

The dropdown components open performance is affected by the # of other dropdown components on the page. I know this is not great UX, but I have a table of ~1000 items which have a dropdown component in one of the cells, similar to the example provided.

http://plnkr.co/edit/IsdAtHkPQ4FnF8kYaRGA?p=preview

ng-bootstrap version: alpha.8

@pkozlowski-opensource
Copy link
Member

Yeh, the global click handler (one that is used to close dropdowns on the outside clicks) is to blame here. Normally it is not an issue since in an app you would have just a limited number of dropdowns.

As you've noticed it isn't a common scenario so you might want to roll out your own version of the dropdown directive that is tailored to your needs. We are going to look at this scenario but not as an immediate priority.

@pkozlowski-opensource
Copy link
Member

One of the potential solutions would be to have a global service that tracks outside clicks and registers all the dropdown directives (it could probably be also useful to track outside clicks for other directives - ex.: datepicker popups).

Here is a sketch of the solution: http://plnkr.co/edit/LvmpFxzCSRjlZCNU8Osm?p=preview
Obviously the above is very hacky (uses DOM API directly, isn't playing great with zones etc.) but that's the general idea.

@wesleycho
Copy link
Member

In the meantime, I'd probably recommend implementing some sort of virtual scrolling to avoid having that many elements rendered at once. It seems like wasteful performance to have that many elements rendered at once.

@ngi80
Copy link

ngi80 commented Nov 17, 2016

Hello,
I have the same issue with a collapse element i applied on a 'card-block'.
Does the solution you mentioned previously could also solve my issue ?

I have a lot of card in card representing a tree of elements.

Thank you,

@thbt
Copy link
Contributor

thbt commented Jan 30, 2017

I found a way to improve the performance using the renderer and dynamically registering listener : http://plnkr.co/edit/SXEy855KQQQYXgjI5Fqc?p=preview
Should I put up a PR with this ?

thbt pushed a commit to thbt/ng-bootstrap that referenced this issue Jan 31, 2017
@daevid66
Copy link

thbt's solution is exactly what I was about to implement, before searching. Please accept his/her pr.

@thbt
Copy link
Contributor

thbt commented Feb 2, 2017

@daevid66 I would like to do a PR but some tests are failing (while it works in the browser)
If you want to help you can check my fork

thbt pushed a commit to thbt/ng-bootstrap that referenced this issue Feb 8, 2017
thbt pushed a commit to thbt/ng-bootstrap that referenced this issue Feb 8, 2017
thbt pushed a commit to thbt/ng-bootstrap that referenced this issue Feb 8, 2017
@laserus
Copy link

laserus commented Feb 10, 2017

@wesleycho Do you have any example of working virtual scroll for ng2?

As far as I know, there is nothing solid and we all are waiting for angular/components#823

@daBishMan
Copy link

when is this going to be merged and released please?

@PatrykTucki
Copy link

Are there any updates on this issue? Using ~30 dropdowns literally kills the app performance.

@mscudlik
Copy link

I think Renderer2 should be used instead of the deprecated Rendererso that it should also work with the angular-universal approach and i suggest to use NgZone so that it runs completely outside of the angular change detection because the change detection is the performance killer here, not the event

@codepwner
Copy link

+1 I need a resolution for this issue please!

@liviu-c
Copy link

liviu-c commented Sep 13, 2017

+1
Any updates on this?
Is this gonna be fixed in the near future?

@pkozlowski-opensource
Copy link
Member

Is this gonna be fixed in the near future?

We should have it covered in one of the next releases.

@daibertdiego
Copy link

+1

@rfrancisco
Copy link

Any news regarding this?

@liviu-c
Copy link

liviu-c commented Dec 17, 2017

nothing new on this?

@kuhlschrank
Copy link

+1

@AntonLebiodkin
Copy link

+1

3 similar comments
@rightisleft
Copy link

+1

@Rayno42
Copy link

Rayno42 commented Mar 6, 2018

+1

@Zak-C
Copy link

Zak-C commented Apr 5, 2018

+1

@germanpa
Copy link

+1

@gpsimmo
Copy link

gpsimmo commented Apr 26, 2018

Is there any update on this issue?!

@rpelavin
Copy link

+1

2 similar comments
@kyrare
Copy link

kyrare commented Jun 4, 2018

+1

@Md-Aman
Copy link

Md-Aman commented Jun 7, 2018

+1

@rysilva
Copy link

rysilva commented Jun 12, 2018

I'd like to just echo that it's not just thousands that will cause this issue, and not always bad UX that causes this issue. We have a tabular UI where each row has two dropdowns. I don't think 50 rows warrants implementing virtual scrolling, but that's 100 dropdowns and a noticeable delay (500ms or more). With 100-200 rows, it's unusuable.

(edit: well that's embarrassing, I didn't realize I was commenting on ng-bootstrap rather than ngx-bootstrap, which I use. Well, I guess my point is probably still valid)

@alfazjikani
Copy link

alfazjikani commented Feb 14, 2020

Issue is being fixed by below work around for ngx-bootstrap dropdown.

`<table>
<tr *ngFor="let item of arr;">
...
<td class="cell-checkbox text-right vmiddle">

<span *ngIf="!item.show" class="fa fa-cog no-space dropdown-toggle pointer m-r" title="Options" (mouseleave)="item.show=false" (mouseenter)="item.show = true"></span>

<div *ngIf="item.show" class="dropdown-holder m-r" dropdown>
 <span dropdownToggle class="fa fa-cog dropdown-toggle pointer" title="Options"></span>
 <ul *dropdownMenu class="dropdown-menu">
  <li role="menuitem">
   <a class="dropdown-item pointer"> Option 1 </a>
  </li>
 </ul>
</div>

</td>
</table>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests