tableDom.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. var count = 1;
  6. function genName(prefix) {
  7. return "X" + count++ + "\n";
  8. }
  9. function appendCell(aRow, aRowSpan, aColSpan) {
  10. var cell = document.createElement("TD", null);
  11. cell.rowSpan = aRowSpan;
  12. cell.colSpan = aColSpan;
  13. var text = document.createTextNode(genName());
  14. cell.appendChild(text);
  15. aRow.appendChild(cell);
  16. }
  17. function appendCellAt(aRowIndex, aRowSpan, aColSpan) {
  18. var row = document.getElementsByTagName("TR")[aRowIndex];
  19. appendCell(row, aRowSpan, aColSpan);
  20. }
  21. function insertCell(aRow, aColIndex, aRowSpan, aColSpan) {
  22. var cells = aRow.cells;
  23. var refCell = cells.item(aColIndex);
  24. var newCell = document.createElement("TD", null);
  25. newCell.rowSpan = aRowSpan;
  26. newCell.colSpan = aColSpan;
  27. var text = document.createTextNode(genName());
  28. newCell.appendChild(text);
  29. aRow.insertBefore(newCell, refCell);
  30. //dump("SCRIPT: inserted CELL as first cell in first row\n");
  31. }
  32. function insertCellAt(aRowIndex, aColIndex, aRowSpan, aColSpan) {
  33. var row = document.getElementsByTagName("TR")[aRowIndex];
  34. insertCell(row, aColIndex, aRowSpan, aColSpan);
  35. }
  36. function deleteCell(aRow, aColIndex) {
  37. aRow.deleteCell(aColIndex);
  38. }
  39. function deleteCellAt(aRowIndex, aColIndex) {
  40. var row = document.getElementsByTagName("TR")[aRowIndex];
  41. deleteCell(row, aColIndex);
  42. }
  43. //function appendRow(aRowGroup) {
  44. // var row = document.createElement("TR", null);
  45. // cell = document.createElement("TD", null);
  46. // row.appendChild(cell);
  47. // aRowGroup.appendChild(row);
  48. //}
  49. function appendRow(aRowGroup) {
  50. var row = document.createElement("TR", null);
  51. cell = document.createElement("TD", null);
  52. aRowGroup.appendChild(row);
  53. //row.appendChild(cell);
  54. //appendCell(row, 1, 1);
  55. }
  56. function appendRowAt(aRowGroupIndex) {
  57. var rowGroup = document.getElementsByTagName("TBODY")[aRowGroupIndex];
  58. appendRow(rowGroup);
  59. }
  60. function insertRow(aRowGroup, aRowIndex) {
  61. var rows = aRowGroup.rows;
  62. var refRow = rows.item(aRowIndex);
  63. var row = document.createElement("TR", null);
  64. aRowGroup.insertBefore(row, refRow);
  65. //appendCell(row, 1, 1);
  66. }
  67. function insertRowAt(aRowGroupIndex, aRowIndex) {
  68. var rowGroup = document.getElementsByTagName("TBODY")[aRowGroupIndex];
  69. insertRow(rowGroup, aRowIndex);
  70. }
  71. function deleteRow(aRowGroup, aRowIndex) {
  72. aRowGroup.deleteRow(aRowIndex);
  73. }
  74. function deleteRowAt(aRowGroupIndex, aRowIndex) {
  75. var row = document.getElementsByTagName("TBODY")[aRowGroupIndex];
  76. deleteRow(row, aRowIndex);
  77. }
  78. function insertTbody(aTable, aTbodyIndex) {
  79. var tbodies = aTable.tBodies;
  80. var refTbody = tbodies.item(aTbodyIndex);
  81. var tbody = document.createElement("TBODY", null);
  82. aTable.insertBefore(tbody, refTbody);
  83. }
  84. function insertTbodyAt(aTableIndex, aTbodyIndex) {
  85. var table = document.getElementsByTagName("TABLE")[aTableIndex];
  86. insertTbodyAt(table, aTbodyIndex);
  87. }
  88. function deleteTbody(aTable, aTbodyIndex) {
  89. var tbodies = aTable.tBodies;
  90. var tbody = tbodies.item(aTbodyIndex);
  91. aTable.removeChild(tbody);
  92. }
  93. function deleteTbodyAt(aTableIndex, aTbodyIndex) {
  94. var table = document.getElementsByTagName("TABLE")[aTableIndex];
  95. deleteTbody(table, aTbodyIndex);
  96. }
  97. function buildTable(aNumRows, aNumCols) {
  98. var table = document.getElementsByTagName("TABLE")[0];
  99. for (rowX = 0; rowX < aNumRows; rowX++) {
  100. var row = document.createElement("TR", null);
  101. for (colX = 0; colX < aNumCols; colX++) {
  102. var cell = document.createElement("TD", null);
  103. var text = document.createTextNode(genName());
  104. cell.appendChild(text);
  105. row.appendChild(cell);
  106. }
  107. table.appendChild(row);
  108. }
  109. }