/public/javascripts/dojo/release/dojo/dojox/grid/tests/test_events.html

http://enginey.googlecode.com/ · HTML · 188 lines · 179 code · 9 blank · 0 comment · 0 complexity · 188bab1e268d8c8128c07aedc364395b MD5 · raw file

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Test dojox.grid.Grid Events</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
  6. <style type="text/css">
  7. @import "../resources/Grid.css";
  8. body,td,th {
  9. font-family: Geneva, Arial, Helvetica, sans-serif;
  10. }
  11. #grid {
  12. border: 1px solid;
  13. border-top-color: #F6F4EB;
  14. border-right-color: #ACA899;
  15. border-bottom-color: #ACA899;
  16. border-left-color: #F6F4EB;
  17. }
  18. #grid {
  19. width: 50em;
  20. height: 20em;
  21. padding: 1px;
  22. overflow: hidden;
  23. font-size: small;
  24. }
  25. h3 {
  26. margin: 10px 0 2px 0;
  27. }
  28. .fade {
  29. /*background-image:url(images/fade.gif);*/
  30. }
  31. .no-fade {
  32. /*background-image: none;*/
  33. }
  34. #eventGrid {
  35. float: right;
  36. font-size: small;
  37. }
  38. </style>
  39. <script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:false, parseOnLoad: true"></script>
  40. <script type="text/javascript">
  41. dojo.require("dojox.grid._Grid");
  42. dojo.require("dojo.parser");
  43. </script>
  44. <script type="text/javascript">
  45. // events to track
  46. var eventRows = [
  47. { name: 'onCellClick' },
  48. { name: 'onRowClick', properties: ['rowIndex'] },
  49. { name: 'onCellDblClick' },
  50. { name: 'onRowDblClick', properties: ['rowIndex'] },
  51. { name: 'onCellMouseOver' },
  52. { name: 'onCellMouseOut' },
  53. { name: 'onCellMouseDown' },
  54. { name: 'onRowMouseOver' },
  55. { name: 'onRowMouseOut' },
  56. { name: 'onRowMouseDown' },
  57. { name: 'onHeaderCellClick' },
  58. { name: 'onHeaderClick', properties: ['rowIndex'] },
  59. { name: 'onHeaderCellDblClick' },
  60. { name: 'onHeaderDblClick', properties: ['rowIndex'] },
  61. { name: 'onHeaderCellMouseOver' },
  62. { name: 'onHeaderCellMouseOut' },
  63. { name: 'onHeaderCellMouseDown' },
  64. { name: 'onHeaderMouseOver' },
  65. { name: 'onHeaderMouseOut' },
  66. { name: 'onKeyDown', properties: ['keyCode'] },
  67. { name: 'onCellContextMenu' },
  68. { name: 'onRowContextMenu', properties: ['rowIndex'] },
  69. { name: 'onHeaderCellContextMenu' },
  70. { name: 'onHeaderContextMenu', properties: ['rowIndex'] }
  71. ];
  72. getEventName = function(inRowIndex) {
  73. return eventRows[inRowIndex].name;
  74. };
  75. getEventData = function(inRowIndex) {
  76. var d = eventRows[inRowIndex].data;
  77. var r = [];
  78. if (d)
  79. for (var i in d)
  80. r.push(d[i]);
  81. else
  82. r.push('na')
  83. return r.join(', ');
  84. }
  85. // grid structure for event tracking grid.
  86. var eventLayout = {
  87. noscroll: true,
  88. cells: [
  89. { name: 'Event', get: getEventName, width: 12 },
  90. { name: 'Data', get: getEventData, width: 10 }
  91. ]
  92. }
  93. var fade = function(inNode) {
  94. if (!inNode || !inNode.style) return;
  95. var c = 150, step = 5, delay = 20;
  96. var animate = function() {
  97. c = Math.min(c + step, 255);
  98. inNode.style.backgroundColor = "rgb(" + c + ", " + c + ", 255)";
  99. if (c < 255) window.setTimeout(animate, delay);
  100. }
  101. animate();
  102. }
  103. // setup a fade on a row. Must do this way to avoid caching of fade gif
  104. updateRowFade = function(inRowIndex) {
  105. var n = eventGrid.views.views[0].getRowNode(inRowIndex);
  106. fade(n);
  107. }
  108. // store data about event. By default track event.rowIndex and event.cell.index, but eventRows can specify params, which are event properties to track.
  109. setEventData = function(inIndex, inEvent) {
  110. var eRow = eventRows[inIndex];
  111. eRow.data = {};
  112. var properties = eRow.properties;
  113. if (properties)
  114. for (var i=0, l=properties.length, p; (p=properties[i] || i < l); i++)
  115. eRow.data[p] = inEvent[p];
  116. else
  117. eRow.data = {
  118. row: (inEvent.rowIndex != undefined ? Number(inEvent.rowIndex) : 'na'),
  119. cell: (inEvent.cell && inEvent.cell.index != undefined ? inEvent.cell.index : 'na')
  120. }
  121. eventGrid.updateRow(inIndex);
  122. updateRowFade(inIndex);
  123. }
  124. // setup grid events for all events being tracked.
  125. setGridEvents = function() {
  126. var makeEvent = function(inIndex, inName) {
  127. return function(e) {
  128. setEventData(inIndex, e);
  129. dojox.grid._Grid.prototype[inName].apply(this, arguments);
  130. }
  131. }
  132. for (var i=0, e; (e=eventRows[i]); i++)
  133. grid[e.name] = makeEvent(i, e.name);
  134. }
  135. // Grid structure
  136. var layout = [// array of view objects
  137. {
  138. noscroll: true,
  139. cells: [[
  140. { name: "Alpha", value: '<input type="checkbox"></input>', rowSpan: 2, width: 6, styles: 'text-align:center;' },
  141. { name: "Alpha2", value: "Alpha2" }
  142. ],[
  143. { name: "Alpha3", value: "Alpha3" }
  144. ]]
  145. },
  146. [
  147. [
  148. { name: "Beta", value: 'simple'},
  149. { name: "Beta2", value: "Beta2" },
  150. { name: "Beta3", value: "Beta3" },
  151. { name: "Beta4", value: "Beta4" },
  152. { name: "Beta5", value: "Beta5" }
  153. ],[
  154. { name: "Summary", colSpan: 5, value: 'Summary' }
  155. ]
  156. ],
  157. {
  158. noscroll: true,
  159. cells: [
  160. { name: "Gamma", value: "Gamma" },
  161. { name: "Gamma2", value: "<button>Radiate</button>", styles: 'text-align:center;' }
  162. ]
  163. }
  164. ];
  165. dojo.addOnLoad(function() {
  166. window["grid"] = dijit.byId("grid");
  167. window["eventGrid"] = dijit.byId("eventGrid");
  168. setGridEvents();
  169. eventGrid.updateRowCount(eventRows.length);
  170. dojo.debug = console.log;
  171. });
  172. </script>
  173. </head>
  174. <body>
  175. <h3>dojox.grid.Grid Event Tracking</h3>
  176. <div id="eventGrid" autoWidth="true" autoHeight="true" structure="eventLayout" dojoType="dojox.grid._Grid"></div>
  177. <div id="grid" rowCount="100" structure="layout" rowSelector="20px" dojoType="dojox.grid._Grid"></div>
  178. </body>
  179. </html>