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

Lazy render bootstrap-select #2187

Closed
grosser opened this issue Feb 1, 2019 · 1 comment
Closed

Lazy render bootstrap-select #2187

grosser opened this issue Feb 1, 2019 · 1 comment

Comments

@grosser
Copy link

grosser commented Feb 1, 2019

Our pages were loading super slow when they had lots of big bootstrap-selects on them,
so I switched it to only actually go through all the work when the element is clicked.
This seems like a simple fix that could solve lots of the performance issues I saw here.

  function convertToLiveSelect(select){
    return $(select)
      .addClass("selectpicker") // hide select and apply styles
      .selectpicker() // apply select picker
  }

  // user tabs into select (and will press down/space next)
  $(".lazy-selectpicker:not(.selectpicker)").one("focus", function(){
    convertToLiveSelect(this)
      .focus(); // focus new element instead
  });

  // user clicks on select
  $(".lazy-selectpicker:not(.selectpicker)").one("mousedown", function(e){
    e.preventDefault(); // do not open real select
    convertToLiveSelect(this)
      .next().click(); // trigger selectpicker
  });

  // multiselects look bad when not rendered
  $(".lazy-selectpicker[multiple]").unbind("mousedown").selectpicker();
@caseyjhol
Copy link
Member

caseyjhol commented Mar 9, 2019

While this exact feature hasn't been added, offloading the initial data calculation via a setTimeout allows the button elements and the rest of the page to load quickly. For large selects, the time in which lazy rendering would really be of benefit, the delay in opening the menu would be too great in my opinion. If people are still running into issues, let me know and I can reopen this issue and address it in a future release. Otherwise, considering this released in v1.13.6!

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

No branches or pull requests

2 participants