Bootstrap drop down cutting off

This is not an ideal solution as the menu will not scroll with the target element, but I’m doing this for a scrolling data table as a last resort until I can find an alternative:

(function() {                                             
  var dropdownMenu;                                     
  $(window).on('show.bs.dropdown', function(e) {        
    dropdownMenu = $(e.target).find('.dropdown-menu');
    $('body').append(dropdownMenu.detach());          
    dropdownMenu.css('display', 'block');             
    dropdownMenu.position({                           
      'my': 'right top',                            
      'at': 'right bottom',                         
      'of': $(e.relatedTarget)                      
    })                                                
  });                                                   
  $(window).on('hide.bs.dropdown', function(e) {        
    $(e.target).append(dropdownMenu.detach());        
    dropdownMenu.hide();                              
  });                                                   
})();                  

This will append the menu to the body and clean it up on hide. I’m using jquery UI for positioning but you can replace it with regular jquery positioning if you don’t want to add the heavy dependency. You may also want to alter $(window).on if you only want to do this to a limited selection of dropdowns.

Leave a Comment