GUI -- Scrollable table working!
Change-Id: I77eb1a620cfa64e44996e8eed09a6be9c9cda202
Showing
1 changed file
with
21 additions
and
55 deletions
| ... | @@ -22,21 +22,32 @@ | ... | @@ -22,21 +22,32 @@ |
| 22 | 'use strict'; | 22 | 'use strict'; |
| 23 | 23 | ||
| 24 | function setColWidth($log, t) { | 24 | function setColWidth($log, t) { |
| 25 | - var tHeaders, tdElement; | 25 | + var tHeaders, tdElement, colWidth; |
| 26 | 26 | ||
| 27 | - // for each th, set its width to td's width | ||
| 28 | - // do this by looping through each td in the first row | ||
| 29 | - // and finding its column width | ||
| 30 | tHeaders = t.selectAll('th'); | 27 | tHeaders = t.selectAll('th'); |
| 31 | - //loop through selectAll array | 28 | + |
| 32 | - tHeaders.forEach(function(thElement){ | 29 | + // select each td in the first row and set the header's width to the |
| 33 | - tdElement = t.filter('nth-child()'); | 30 | + // corresponding td's width, if td is larger than header's width |
| 34 | - $log.log(thElement); | 31 | + tHeaders.each(function(thElement, index){ |
| 32 | + thElement = d3.select(this); | ||
| 33 | + | ||
| 34 | + tdElement = t.select('td:nth-of-type(' + (index + 1) + ')'); | ||
| 35 | + colWidth = tdElement.style('width'); | ||
| 36 | + | ||
| 37 | + thElement.style('width', colWidth); | ||
| 38 | + tdElement.style('width', colWidth); | ||
| 39 | + //thElement.style('color', 'blue'); | ||
| 40 | + //tdElement.style('color', 'red'); | ||
| 41 | + | ||
| 35 | }); | 42 | }); |
| 36 | } | 43 | } |
| 37 | 44 | ||
| 38 | function setCSS(thead, tbody) { | 45 | function setCSS(thead, tbody) { |
| 39 | - | 46 | + thead.style('display', 'block'); |
| 47 | + tbody.style({'display': 'block', | ||
| 48 | + 'height': '100px', | ||
| 49 | + 'overflow': 'auto' | ||
| 50 | + }); | ||
| 40 | } | 51 | } |
| 41 | 52 | ||
| 42 | function trimTable(tbody) { | 53 | function trimTable(tbody) { |
| ... | @@ -74,7 +85,7 @@ | ... | @@ -74,7 +85,7 @@ |
| 74 | $timeout(function() { | 85 | $timeout(function() { |
| 75 | $log.log('timeout is over'); | 86 | $log.log('timeout is over'); |
| 76 | fixTable($log, table, thead, tbody); | 87 | fixTable($log, table, thead, tbody); |
| 77 | - }, 200); | 88 | + }); |
| 78 | } | 89 | } |
| 79 | }); | 90 | }); |
| 80 | $log.log('fixedHeader directive has been created'); | 91 | $log.log('fixedHeader directive has been created'); |
| ... | @@ -82,48 +93,3 @@ | ... | @@ -82,48 +93,3 @@ |
| 82 | }; | 93 | }; |
| 83 | }]); | 94 | }]); |
| 84 | }()); | 95 | }()); |
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 85 | - | ||
| 86 | -$scope.$watch(function () { return $elem.find("tbody").is(':visible') }, | ||
| 87 | - function (newValue, oldValue) { | ||
| 88 | - if (newValue === true) { | ||
| 89 | - // reset display styles so column widths are correct when measured below | ||
| 90 | - $elem.find('thead, tbody, tfoot').css('display', ''); | ||
| 91 | - | ||
| 92 | - // wrap in $timeout to give table a chance to finish rendering | ||
| 93 | - $timeout(function () { | ||
| 94 | - // set widths of columns | ||
| 95 | - $elem.find('th').each(function (i, thElem) { | ||
| 96 | - thElem = $(thElem); | ||
| 97 | - var tdElems = $elem.find('tbody tr:first td:nth-child(' + (i + 1) + ')'); | ||
| 98 | - var tfElems = $elem.find('tfoot tr:first td:nth-child(' + (i + 1) + ')'); | ||
| 99 | - | ||
| 100 | - var columnWidth = tdElems.width(); | ||
| 101 | - thElem.width(columnWidth); | ||
| 102 | - tdElems.width(columnWidth); | ||
| 103 | - tfElems.width(columnWidth); | ||
| 104 | - }); | ||
| 105 | - | ||
| 106 | - // set css styles on thead and tbody | ||
| 107 | - $elem.find('thead, tfoot').css({ | ||
| 108 | - 'display': 'block', | ||
| 109 | - }); | ||
| 110 | - | ||
| 111 | - $elem.find('tbody').css({ | ||
| 112 | - 'display': 'block', | ||
| 113 | - 'height': $scope.tableHeight || '400px', | ||
| 114 | - 'overflow': 'auto' | ||
| 115 | - }); | ||
| 116 | - | ||
| 117 | - // reduce width of last column by width of scrollbar | ||
| 118 | - var scrollBarWidth = $elem.find('thead').width() - $elem.find('tbody')[0].clientWidth; | ||
| 119 | - if (scrollBarWidth > 0) { | ||
| 120 | - // for some reason trimming the width by 2px lines everything up better | ||
| 121 | - scrollBarWidth -= 2; | ||
| 122 | - $elem.find('tbody tr:first td:last-child').each(function (i, elem) { | ||
| 123 | - $(elem).width($(elem).width() - scrollBarWidth); | ||
| 124 | - }); | ||
| 125 | - } | ||
| 126 | - }); | ||
| 127 | - } | ||
| 128 | - }); | ||
| 129 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment