TableContainer.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. if (!dojo._hasResource["dojox.wire.demos.TableContainer"]) { // _hasResource
  2. // checks added
  3. // by build. Do
  4. // not use
  5. // _hasResource
  6. // directly in
  7. // your code.
  8. dojo._hasResource["dojox.wire.demos.TableContainer"] = true;
  9. dojo.provide("dojox.wire.demos.TableContainer");
  10. dojo.require("dojo.parser");
  11. dojo.require("dijit._Widget");
  12. dojo.require("dijit._Templated");
  13. dojo.declare("dojox.wire.demos.TableContainer", [dijit._Widget,
  14. dijit._Templated, dijit._Container], {
  15. // summary:
  16. // Extremely simple 'widget' that is a table generator with an
  17. // addRow function that takes an array
  18. // as the row to add, where each entry is a cell in the row.
  19. // This demo widget is for use with the
  20. // wire demos.
  21. templateString : "<table class='tablecontainer'><tbody dojoAttachPoint='tableContainer'></tbody></table>",
  22. rowCount : 0,
  23. headers : "",
  24. addRow : function(array) {
  25. // summary:
  26. // Function to add in a new row from the elements in the
  27. // array map to cells in the row.
  28. // array:
  29. // Array of row values to add.
  30. try {
  31. var row = document.createElement("tr");
  32. if ((this.rowCount % 2) === 0) {
  33. dojo.addClass(row, "alternate");
  34. }
  35. this.rowCount++;
  36. for (var i in array) {
  37. var cell = document.createElement("td");
  38. var text = document.createTextNode(array[i]);
  39. cell.appendChild(text);
  40. row.appendChild(cell);
  41. }
  42. this.tableContainer.appendChild(row);
  43. } catch (e) {
  44. console.debug(e);
  45. }
  46. },
  47. clearTable : function() {
  48. // summary:
  49. // Function to clear all the current rows in the table,
  50. // except for the header.
  51. // Always leave the first row, which is the table header.
  52. while (this.tableContainer.firstChild.nextSibling) {
  53. this.tableContainer
  54. .removeChild(this.tableContainer.firstChild.nextSibling);
  55. }
  56. this.rowCount = 0;
  57. },
  58. postCreate : function() {
  59. // summary:
  60. // Widget lifecycle function to handle generation of the
  61. // header elements in the table.
  62. var headers = this.headers.split(",");
  63. var tr = document.createElement("tr");
  64. for (i in headers) {
  65. var header = headers[i];
  66. var th = document.createElement("th");
  67. var text = document.createTextNode(header);
  68. th.appendChild(text);
  69. tr.appendChild(th);
  70. }
  71. this.tableContainer.appendChild(tr);
  72. }
  73. });
  74. }