最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to improve prime ng dropdown performance for huge data - Stack Overflow

programmeradmin0浏览0评论

I have used primeng multi-select dropdown in our angular project. But the data which we need to load is very huge like 4-5K elements. So my dropdown takes 10 seconds during loading.

Please suggest me the way to improve the performance to create the multi-select dropdown.

I have used primeng multi-select dropdown in our angular project. But the data which we need to load is very huge like 4-5K elements. So my dropdown takes 10 seconds during loading.

Please suggest me the way to improve the performance to create the multi-select dropdown.

Share Improve this question asked Dec 25, 2017 at 6:04 Ishant GauravIshant Gaurav 1,2034 gold badges15 silver badges34 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 15

PrimeNG v8 (and, in my experience, v7) has two documented properties that involve improving performance of MultiSelect inputs with very long lists of options:

[virtualScroll]="true" itemSize="30"

virtualScroll enables the basic performance enhancement but failing to set the itemSize value prevents improved performance.

itemSize affects the amount of vertical space allotted to options in the displayed options panel and 30 provides an acceptable height for rendering a checkbox and adjacent single line of text for each option in that panel.

Typically, when using MultiSelect templating with images or options larger than a single line of text, increasing the itemSize appropriately will be necessary. (Though less likely, you might be able to cram more entries in with a smaller font and a reduced itemSize.)

See "Virtual Scrolling" section of "Documentation" tab in the primefaces.org PrimeNG documentation for MultiSelect.

You should fork primeng repo and change implementation in multiselect component (line 51)

It uses *ngFor ti list values, but you should change it with ng2-vs-for

The difference beweeet ngFor and vs-for is that not all elements added to the dom at once, but only the items you should see according to the scroll position.

Rather than fork the library, which leaves you stuck on a specific version, I identified which dropdowns had so many values that they were lagging and changed these primeng dropdowns for primeng autocompletes and the lag was gone.

发布评论

评论列表(0)

  1. 暂无评论