callbacks.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Callbacks - Handsontable</title>
  6. <!--
  7. Loading Handsontable (full distribution that includes all dependencies apart from jQuery)
  8. -->
  9. <script data-jsfiddle="common" src="../demo/js/jquery.min.js"></script>
  10. <link data-jsfiddle="common" rel="stylesheet" media="screen" href="../dist/handsontable.css">
  11. <link data-jsfiddle="common" rel="stylesheet" media="screen" href="../dist/pikaday/pikaday.css">
  12. <script data-jsfiddle="common" src="../dist/pikaday/pikaday.js"></script>
  13. <script data-jsfiddle="common" src="../dist/moment/moment.js"></script>
  14. <script data-jsfiddle="common" src="../dist/zeroclipboard/ZeroClipboard.js"></script>
  15. <script data-jsfiddle="common" src="../dist/numbro/numbro.js"></script>
  16. <script data-jsfiddle="common" src="../dist/numbro/languages.js"></script>
  17. <script data-jsfiddle="common" src="../dist/handsontable.js"></script>
  18. <!--
  19. Loading demo dependencies. They are used here only to enhance the examples on this page
  20. -->
  21. <link data-jsfiddle="common" rel="stylesheet" media="screen" href="css/samples.css?20140331">
  22. <script src="js/samples.js"></script>
  23. <script src="js/highlight/highlight.pack.js"></script>
  24. <link rel="stylesheet" media="screen" href="js/highlight/styles/github.css">
  25. <link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css">
  26. <script src="js/json2.min.js"></script>
  27. <!--
  28. Facebook open graph. Don't copy this to your project :)
  29. -->
  30. <meta property="og:title" content="Callbacks">
  31. <meta property="og:description"
  32. content="This page shows usage of some callbacks available in Handsontable">
  33. <meta property="og:url" content="http://handsontable.com/demo/callbacks.html">
  34. <meta property="og:image" content="http://handsontable.com/demo/image/og-image.png">
  35. <meta property="og:image:type" content="image/png">
  36. <meta property="og:image:width" content="409">
  37. <meta property="og:image:height" content="164">
  38. <link rel="canonical" href="http://handsontable.com/demo/callbacks.html">
  39. <!--
  40. Google Analytics for GitHub Page. Don't copy this to your project :)
  41. -->
  42. <script src="js/ga.js"></script>
  43. </head>
  44. <body>
  45. <div class="wrapper">
  46. <div class="wrapper-row">
  47. <div id="global-menu-clone">
  48. <h1><a href="../index.html">Handsontable</a></h1>
  49. </div>
  50. <div id="container">
  51. <div class="columnLayout">
  52. <div class="rowLayout">
  53. <div class="descLayout">
  54. <div class="pad" data-jsfiddle="example1">
  55. <h2>Callbacks</h2>
  56. <p>
  57. This page shows usage of some callbacks available in Handsontable. Full list of callbacks is available in <a
  58. href="https://github.com/handsontable/handsontable">README.md</a>.
  59. </p>
  60. <p>
  61. If you require a new callback to be added to Handsontable, please open an <a
  62. href="https://github.com/handsontable/handsontable/issues">Issue</a>.
  63. </p>
  64. <p>
  65. Note that some checkboxes below are initially unchecked (not all callbacks are displayed on this page by default).
  66. </p>
  67. <div id="example1"></div>
  68. <p>
  69. <button name="dump" data-dump="#example1" data-instance="hot" title="Prints current data source to Firebug/Chrome Dev Tools">
  70. Dump data to console
  71. </button>
  72. </p>
  73. <h3>Events log
  74. <button onclick="$('#example1_events').empty()">
  75. Clear
  76. </button>
  77. </h3>
  78. <div id="example1_events"
  79. style="height: 250px; overflow: hidden; background-color: #fdfdfd; font-size: 11px"></div>
  80. <p>Choose events to be logged:</p>
  81. <ul class="tight" id="hooksList">
  82. <li><label><input type="checkbox" id="check_select_all"> <strong>select all</strong></label></li>
  83. </ul>
  84. </div>
  85. </div>
  86. <div class="codeLayout">
  87. <div class="pad">
  88. <div class="jsFiddle">
  89. <button class="jsFiddleLink" data-runfiddle="example1">Edit in jsFiddle</button>
  90. </div>
  91. <script data-jsfiddle="example1">
  92. var data = [
  93. ['', 'Maserati', 'Mazda', 'Mercedes', 'Mini', 'Mitsubishi'],
  94. ['2009', 0, 2941, 4303, 354, 5814],
  95. ['2010', 3, 2905, 2867, 412, 5284],
  96. ['2011', 4, 2517, 4822, 552, 6127],
  97. ['2012', 2, 2422, 5399, 776, 4151]
  98. ],
  99. example1 = document.getElementById('example1'),
  100. config,
  101. $hooksList,
  102. hooks,
  103. hot;
  104. config = {
  105. data: data,
  106. minRows: 5,
  107. minCols: 6,
  108. minSpareRows: 1,
  109. autoWrapRow: true,
  110. colHeaders: true,
  111. contextMenu: true
  112. };
  113. $hooksList = $('#hooksList');
  114. hooks = Handsontable.hooks.getRegistered();
  115. hooks.forEach(function(hook) {
  116. var checked = '';
  117. if (hook !== 'modifyRowHeight' && hook !== 'modifyRow' && hook !== 'modifyCol' &&
  118. hook !== 'afterRenderer' && hook !== 'beforeGetCellMeta' && hook !== 'afterGetCellMeta') {
  119. checked = 'checked';
  120. }
  121. $hooksList.append('<li><label><input type="checkbox" ' + checked + ' id="check_' + hook + '"> ' + hook + '</label></li>');
  122. config[hook] = function() {
  123. log_events(hook, arguments);
  124. }
  125. });
  126. var start = (new Date()).getTime();
  127. var i = 0;
  128. var timer;
  129. var example1_events = document.getElementById("example1_events");
  130. function log_events(event, data) {
  131. if (document.getElementById('check_' + event).checked) {
  132. var now = (new Date()).getTime(),
  133. diff = now - start,
  134. vals, str, div, text;
  135. vals = [
  136. i,
  137. "@" + numbro(diff / 1000).format('0.000'),
  138. "[" + event + "]"
  139. ];
  140. for (var d = 0; d < data.length; d++) {
  141. try {
  142. str = JSON.stringify(data[d]);
  143. }
  144. catch (e) {
  145. str = data[d].toString(); // JSON.stringify breaks on circular reference to a HTML node
  146. }
  147. if (str === void 0) {
  148. continue;
  149. }
  150. if (str.length > 20) {
  151. str = Object.prototype.toString.call(data[d]);
  152. }
  153. if (d < data.length - 1) {
  154. str += ',';
  155. }
  156. vals.push(str);
  157. }
  158. if (window.console) {
  159. console.log(i,
  160. "@" + numbro(diff / 1000).format('0.000'),
  161. "[" + event + "]",
  162. data);
  163. }
  164. div = document.createElement("DIV");
  165. text = document.createTextNode(vals.join(" "));
  166. div.appendChild(text);
  167. example1_events.appendChild(div);
  168. clearTimeout(timer);
  169. timer = setTimeout(function() {
  170. example1_events.scrollTop = example1_events.scrollHeight;
  171. }, 10);
  172. i++;
  173. }
  174. }
  175. example1 = document.getElementById('example1');
  176. hot = new Handsontable(example1,config);
  177. $('#check_select_all').click(function () {
  178. var state = this.checked;
  179. $('input[type=checkbox]').each(function () {
  180. if (state === true) {
  181. if (this.id === 'check_modifyRow') {
  182. return; //too much noise in the log
  183. }
  184. }
  185. this.checked = state;
  186. });
  187. });
  188. $('input[type=checkbox]').click(function () {
  189. if (!this.checked) {
  190. document.getElementById('check_select_all').checked = false;
  191. }
  192. });
  193. </script>
  194. </div>
  195. </div>
  196. </div>
  197. <div class="footer-text">
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. <div id="outside-links-wrapper"></div>
  204. </body>
  205. </html>