demo_DataDemoTable.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Dojo Visual Loader Test</title>
  6. <style type="text/css">
  7. @import "../../../dojo/resources/dojo.css";
  8. @import "../../../dijit/themes/tundra/tundra.css";
  9. @import "../../../dijit/themes/dijit.css";
  10. @import "../../../dijit/tests/css/dijitTests.css";
  11. .oddRow { background-color: #f2f5f9; }
  12. .population { text-align: right; }
  13. </style>
  14. <script type="text/javascript" src="../../../dojo/dojo.js"
  15. djConfig="isDebug: false, parseOnLoad: true"></script>
  16. <script type="text/javascript">
  17. dojo.require("dijit.dijit");
  18. dojo.require("dojo.parser");
  19. dojo.require("dijit.Declaration");
  20. dojo.require("dojo.data.ItemFileReadStore");
  21. dojo.require("dojox.data.FlickrStore");
  22. </script>
  23. </head>
  24. <body class="tundra">
  25. <span dojoType="dojo.data.ItemFileReadStore"
  26. jsId="continentStore"
  27. url="../../../dijit/tests/_data/countries.json"></span>
  28. <span dojoType="dojox.data.FlickrStore" jsId="flickrStore"></span>
  29. <h1 class="testTitle">Dojox Data Demo Table</h1>
  30. <table dojoType="dijit.Declaration"
  31. widgetClass="demo.Table" class="dojoTabular"
  32. defaults="{ store: null, query: { query: { name: '*' } }, columns: [ { name: 'Name', attribute: 'name' } ] }">
  33. <thead dojoAttachPoint="head">
  34. <tr dojoAttachPoint="headRow"></tr>
  35. </thead>
  36. <tbody dojoAttachPoint="body">
  37. <tr dojoAttachPoint="row">
  38. </tr>
  39. </tbody>
  40. <script type="dojo/method">
  41. dojo.forEach(this.columns, function(item, idx){
  42. var icn = item.className||"";
  43. // add a header for each column
  44. var tth = document.createElement("th");
  45. tth.innerHTML = item.name;
  46. tth.className = icn;
  47. dojo.connect(tth, "onclick", dojo.hitch(this, "onSort", idx));
  48. this.headRow.appendChild(tth);
  49. // and fill in the column cell in the template row
  50. this.row.appendChild(document.createElement("td"));
  51. this.row.lastChild.className = icn;
  52. }, this);
  53. this.runQuery();
  54. </script>
  55. <script type="dojo/method" event="onSort" args="index">
  56. var ca = this.columns[index].attribute;
  57. var qs = this.query.sort;
  58. // clobber an existing sort arrow
  59. dojo.query("> th", this.headRow).styles("background", "").styles("paddingRight", "");
  60. if(qs && qs[0].attribute == ca){
  61. qs[0].descending = !qs[0].descending;
  62. }else{
  63. this.query.sort = [{
  64. attribute: ca,
  65. descending: false
  66. }];
  67. }
  68. var th = dojo.query("> th", this.headRow)[index];
  69. th.style.paddingRight = "16px"; // space for the sort arrow
  70. th.style.background = "url(\""+dojo.moduleUrl("dijit", "themes/tundra/images/arrow"+(this.query.sort[0].descending ? "Up" : "Down")+((dojo.isIE == 6) ? ".gif" : ".png")) + "\") no-repeat 98% 4px";
  71. this.runQuery();
  72. </script>
  73. <script type="dojo/method" event="runQuery">
  74. this.query.onBegin = dojo.hitch(this, function(){ dojo.query("tr", this.body).orphan(); });
  75. this.query.onItem = dojo.hitch(this, "onItem");
  76. this.query.onComplete = dojo.hitch(this, function(){
  77. dojo.query("tr:nth-child(odd)", this.body).addClass("oddRow");
  78. dojo.query("tr:nth-child(even)", this.body).removeClass("oddRow");
  79. });
  80. this.store.fetch(this.query);
  81. </script>
  82. <script type="dojo/method" event="onItem" args="item">
  83. var tr = this.row.cloneNode(true);
  84. dojo.query("td", tr).forEach(function(n, i, a){
  85. var tc = this.columns[i];
  86. var tv = this.store.getValue(item, tc.attribute)||"";
  87. if(tc.format){ tv = tc.format(tv, item, this.store); }
  88. n.innerHTML = tv;
  89. }, this);
  90. this.body.appendChild(tr);
  91. </script>
  92. </table>
  93. <span dojoType="demo.Table" store="continentStore"
  94. query="{ query: { type: 'country' }, sort: [ { attribute: 'name', descending: true } ] }"
  95. id="foo">
  96. <script type="dojo/method" event="preamble">
  97. this.columns = [
  98. { name: "Name", attribute: "name" },
  99. { name: "Population",
  100. attribute: "population",
  101. className: "population"
  102. }
  103. ];
  104. </script>
  105. </span>
  106. <span dojoType="demo.Table" store="continentStore"
  107. query="{ query: { name: 'A*' } }"></span>
  108. <span dojoType="demo.Table" store="flickrStore"
  109. query="{ query: { tags: '3dny' } }">
  110. <script type="dojo/method" event="preamble">
  111. this.columns = [
  112. { name: "", attribute: "imageUrlSmall",
  113. format: function(value, item, store){
  114. return (value.length) ? "<img src='"+value+"'>" : "";
  115. }
  116. },
  117. { name: "Title", attribute: "title" }
  118. ];
  119. </script>
  120. </span>
  121. </body>
  122. </html>