Advertisement
DataCCIW

List Report View Top Horizontal Scroll

Nov 25th, 2020
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div class="TableScroller" style="height: 20px; overflow-x: scroll; display: none;">
  2.     <div class="TableSize" style="height: 20px;"></div>
  3. </div>
  4.  
  5. <script>
  6.     $().ready(function () {
  7.         //The code in this .ready function will dynamically set the widths of the divs above creating
  8.         // an additional scroll bar at the top of the data grid when there is a scroll bar at the bottom
  9.  
  10.         // Mutation example per https://stackoverflow.com/questions/15657686/jquery-event-detect-changes-to-the-html-text-of-a-div
  11.         // select the target node
  12.         var target = document.querySelector(".RadGrid_Silk");
  13.         // create an observer instance
  14.         var observer = new MutationObserver(function (mutations) {
  15.             //console.log('Mutation Observed');
  16.  
  17.             var parentWidth = $(".table-responsive").width();
  18.             var childWidth = $(".RadGrid_Silk").width();
  19.  
  20.             // if these widths are the same then no scroll bar is necessary
  21.             if (parentWidth != childWidth) {
  22.                 $(".TableScroller").width(parentWidth);
  23.                 $(".TableSize").width(childWidth);
  24.                 $(".TableScroller").show();
  25.             }
  26.         });
  27.         // configuration of the observer:
  28.         var config = { attributes: true, childList: true, characterData: true };
  29.         // pass in the target node, as well as the observer options
  30.         observer.observe(target, config);
  31.     });
  32.  
  33.     // Per https://jsfiddle.net/TBnqw/1/
  34.     // tie our custom scroll bar at the top to the bottom scroll bar
  35.     $(function () {
  36.         $(".TableScroller").scroll(function () {
  37.             $(".table-responsive").scrollLeft($(".TableScroller").scrollLeft());
  38.         });
  39.         $(".table-responsive").scroll(function () {
  40.             $(".TableScroller").scrollLeft($(".table-responsive").scrollLeft());
  41.         });
  42.     });
  43. </script>
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement