fixedTables.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. var a_fixedTableNames = [];
  17. function initFixedTables(fixedTableNames)
  18. {
  19. if (typeof fixedTableNames != 'undefined')
  20. a_fixedTableNames = a_fixedTableNames.concat( fixedTableNames );
  21. var nFixedTables = a_fixedTableNames.length;
  22. if (nFixedTables) {
  23. document.body.onresize=resizeFixedTableBodyDivs;
  24. for (var i=0; i<a_fixedTableNames.length; i++) {
  25. bDiv = document.getElementById('DB.' + a_fixedTableNames[i]);
  26. bDiv.onscroll = new Function( "scrollFixedTableHeaderDiv(this, '" + a_fixedTableNames[i] + "')" );
  27. }
  28. resizeFixedTableBodyDivs();
  29. }
  30. }
  31. function resizeFixedTableBodyDivs() {
  32. if (a_fixedTableNames.length == 0)
  33. return;
  34. var hfooter = document.getElementById('pageFooter');
  35. var bottom = hfooter ? hfooter.offsetTop : document.body.offsetHeight;
  36. var bDiv = document.getElementById('DB.' + a_fixedTableNames[0]);
  37. var bTable = document.getElementById(a_fixedTableNames[0]);
  38. var h = bottom - bDiv.offsetTop - 35;
  39. h /= a_fixedTableNames.length;
  40. h = Math.max(h, 50);
  41. if (bDiv.offsetHeight > h)
  42. bDiv.style.height = h;
  43. else
  44. {
  45. var tw = bTable.offsetWidth;
  46. var th = bTable.offsetHeight;
  47. var dw = bDiv.offsetWidth;
  48. var doubleBorder = 2;
  49. if (dw < tw+doubleBorder)
  50. bDiv.style.height = Math.min(h, th+20);//add height to fit horiz scrollbar to avoid vertical scrollbar
  51. else
  52. if (dw > tw+doubleBorder)
  53. bDiv.style.height = th+doubleBorder;
  54. }
  55. resizeFixedTableHeaderDiv(bDiv, a_fixedTableNames[0])
  56. for (var i=1; i<a_fixedTableNames.length; i++) {
  57. bDiv = document.getElementById('DB.' + a_fixedTableNames[i]);
  58. bDiv.style.height = h;
  59. resizeFixedTableHeaderDiv(bDiv, a_fixedTableNames[i]);
  60. }
  61. }
  62. function scrollFixedTableHeaderDiv(bodyDiv, tableId)
  63. {
  64. var htable = document.getElementById('H.' + tableId);
  65. if (htable)
  66. htable.style.left = -bodyDiv.scrollLeft;
  67. }
  68. function resizeFixedTableHeaderDiv(bodyDiv, tableId)
  69. {
  70. var hdiv = document.getElementById('DH.' + tableId);
  71. if (hdiv)
  72. {
  73. var htable = document.getElementById('H.' + tableId);
  74. var btable = bodyDiv.getElementsByTagName('table')[0];
  75. hdiv.style.width = bodyDiv.offsetWidth;
  76. htable.style.width = btable.offsetWidth;
  77. //resize individual column headers based on first row's cells in body table
  78. if (htable.style.tableLayout != 'fixed')
  79. {
  80. var bCells = btable.rows[0].cells;
  81. var hCells = htable.rows[0].cells;
  82. var n_bCells = bCells.length;
  83. var n_hCells = hCells.length;
  84. for (var i=0; i<n_bCells; i++)
  85. hCells[i].style.width = bCells[i].offsetWidth;
  86. }
  87. scrollFixedTableHeaderDiv(bodyDiv, tableId);
  88. }
  89. }