Created
June 12, 2015 02:50
-
-
Save wellwind/8ca3a4d1568f18619574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| $('.dropdown-menu').parent().on('show.bs.dropdown', function () { | |
| var parentResponsiveTable = $(this).parents('.table-responsive'); | |
| var parentTarget = $(parentResponsiveTable).first().hasClass('table-responsive') ? $(parentResponsiveTable) : $(window); | |
| var parentTop = $(parentResponsiveTable).first().hasClass('table-responsive') ? $(parentResponsiveTable).offset().top : 0; | |
| var parentLeft = $(parentResponsiveTable).first().hasClass('table-responsive') ? $(parentResponsiveTable).offset().left : 0; | |
| var dropdownMenu = $(this).children('.dropdown-menu').first(); | |
| if (!$(this).hasClass('dropdown') && !$(this).hasClass('dropup')) { | |
| $(this).addClass('dropdown'); | |
| } | |
| $(this).attr('olddrop', $(this).hasClass('dropup') ? 'dropup' : 'dropdown'); | |
| $(this).children('.dropdown-menu').each(function () { | |
| $(this).attr('olddrop-pull', $(this).hasClass('dropdown-menu-right') ? 'dropdown-menu-right' : ''); | |
| }); | |
| if ($(this).hasClass('dropdown')) { | |
| if ($(this).offset().top + $(this).height() + $(dropdownMenu).height() + 10 >= parentTop + $(parentTarget).height()) { | |
| $(this).removeClass('dropdown'); | |
| $(this).addClass('dropup'); | |
| } | |
| } else if ($(this).hasClass('dropup')) { | |
| if ($(this).offset().top - $(dropdownMenu).height() - 10 <= parentTop) { | |
| $(this).removeClass('dropup'); | |
| $(this).addClass('dropdown'); | |
| } | |
| } | |
| if ($(this).offset().left + $(dropdownMenu).width() >= parentLeft + $(parentTarget).width()) { | |
| $(this).children('.dropdown-menu').addClass('dropdown-menu-right'); | |
| } | |
| }); | |
| $('.dropdown-menu').parent().on('hide.bs.dropdown', function () { | |
| if ($(this).attr('olddrop') != '') { | |
| $(this).removeClass('dropup dropdown'); | |
| $(this).addClass($(this).attr('olddrop')); | |
| $(this).attr('olddrop', ''); | |
| } | |
| $(this).children('.dropdown-menu').each(function () { | |
| $(this).removeClass('dropdown-menu-right'); | |
| $(this).addClass($(this).attr('olddrop-pull')); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To avoid DataTable overflow, add this codes:
In show trigger:
$(this).closest('.table-scrollable').css('overflow', 'visible');In hide trigger:
$(this).closest('.table-scrollable').css('overflow', '');Can be put wherever you want, inside triggers!
Example:
Before:
After: