user984621 February 2016

Select tag with many items takes time to render

I have a form with a select tag containing nearly 17k items.

<%= f.select :company_industry_id, options_for_select(@company_industries.map{
 |c| [c.name, c.id] }, selected_key = @company.company_industry_id),
 {}, {:class => 'input_text'} %>

Loading data for @company_industries takes like 0.01s.

@company_industries = CompanyIndustry.select(:id, :name).order('name ASC')

However, rendering it in the f.select box takes about 18 seconds (without having this f.select element in the form, the page is rendered in 350-400ms).

How do I avoid this slowdown? Is there a way to optimize the f.select element? Or, is there some alternative to f.select?

Answers


Nermin February 2016

I would suggest select2

And best approach would be to not load data immediately, but when user types in 3 letters, then you show the data filtered with those 3 letters. It also gives you nice way to search trough you 17k elements, to faster find result.

Post Status

Asked in February 2016
Viewed 1,227 times
Voted 9
Answered 1 times

Search




Leave an answer