dropdownmenu.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <!doctype html>
  2. <html xmlns="http://www.w3.org/1999/html">
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Dropdown Menu - Handsontable</title>
  6. <!--
  7. Loading Handsontable (full distribution that includes all dependencies apart from jQuery)
  8. -->
  9. <link data-jsfiddle="common" rel="stylesheet" media="screen" href="../dist/handsontable.css">
  10. <link data-jsfiddle="common" rel="stylesheet" media="screen" href="../dist/pikaday/pikaday.css">
  11. <script data-jsfiddle="common" src="../dist/pikaday/pikaday.js"></script>
  12. <script data-jsfiddle="common" src="../dist/moment/moment.js"></script>
  13. <script data-jsfiddle="common" src="../dist/zeroclipboard/ZeroClipboard.js"></script>
  14. <script data-jsfiddle="common" src="../dist/numbro/numbro.js"></script>
  15. <script data-jsfiddle="common" src="../dist/numbro/languages.js"></script>
  16. <script data-jsfiddle="common" src="../dist/handsontable.js"></script>
  17. <!--
  18. Loading demo dependencies. They are used here only to enhance the examples on this page
  19. -->
  20. <link data-jsfiddle="common" rel="stylesheet" media="screen" href="css/samples.css?20140331">
  21. <script src="js/samples.js"></script>
  22. <script src="js/highlight/highlight.pack.js"></script>
  23. <link rel="stylesheet" media="screen" href="js/highlight/styles/github.css">
  24. <link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css">
  25. <!--
  26. Facebook open graph. Don't copy this to your project :)
  27. -->
  28. <meta property="og:title" content="Context Menu">
  29. <meta property="og:description"
  30. content="This page shows how to use and configure right-click context menu with Handsontable">
  31. <meta property="og:url" content="http://handsontable.com/demo/contextmenu.html">
  32. <meta property="og:image" content="http://handsontable.com/demo/image/og-image.png">
  33. <meta property="og:image:type" content="image/png">
  34. <meta property="og:image:width" content="409">
  35. <meta property="og:image:height" content="164">
  36. <link rel="canonical" href="http://handsontable.com/demo/contextmenu.html">
  37. <!--
  38. Google Analytics for GitHub Page. Don't copy this to your project :)
  39. -->
  40. <script src="js/ga.js"></script>
  41. </head>
  42. <body>
  43. <div class="wrapper">
  44. <div class="wrapper-row">
  45. <div id="global-menu-clone">
  46. <h1><a href="../index.html">Handsontable</a></h1>
  47. </div>
  48. <div id="container">
  49. <div class="columnLayout">
  50. <div class="rowLayout">
  51. <div class="descLayout">
  52. <div class="pad">
  53. <h2>Dropdown Menu</h2>
  54. <p>This page shows how to use and configure dropdown menu with Handsontable:</p>
  55. <ul>
  56. <li><a href="#default">dropdown menu with default options</a></li>
  57. <li><a href="#specific">dropdown menu with specific options</a></li>
  58. <li><a href="#custom">dropdown menu with fully custom configuration</a></li>
  59. </ul>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="rowLayout">
  64. <div class="descLayout">
  65. <div class="pad" data-jsfiddle="example1">
  66. <a name="default"></a>
  67. <h2>Dropdown Menu with default options</h2>
  68. <p>Tu run the basic configuration of the Dropdown Menu, just set the dropdownMenu option to true.</p>
  69. <div id="example1"></div>
  70. <p>
  71. <button name="dump" data-dump="#example1" data-instance="hot1" title="Prints current data source to Firebug/Chrome Dev Tools">Dump
  72. data to console
  73. </button>
  74. </p>
  75. </div>
  76. </div>
  77. <div class="codeLayout">
  78. <div class="pad">
  79. <div class="jsFiddle">
  80. <button class="jsFiddleLink" data-runfiddle="example1">Edit in jsFiddle</button>
  81. </div>
  82. <script data-jsfiddle="common">
  83. function getData() {
  84. return [
  85. ['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
  86. ['2008', 10, 11, 12, 13],
  87. ['2009', 20, 11, 14, 13],
  88. ['2010', 30, 15, 12, 13]
  89. ];
  90. }
  91. </script>
  92. <script data-jsfiddle="example1">
  93. var example1 = document.getElementById('example1'),
  94. settings1,
  95. hot1;
  96. settings1 = {
  97. data: getData(),
  98. startRows: 5,
  99. startCols: 5,
  100. minRows: 5,
  101. minCols: 5,
  102. maxRows: 10,
  103. maxCols: 10,
  104. rowHeaders: true,
  105. colHeaders: true, // If you use `dropdownMenu` option you must enable colHeaders
  106. minSpareRows: 1,
  107. dropdownMenu: true
  108. };
  109. hot1 = new Handsontable(example1, settings1);
  110. </script>
  111. </div>
  112. </div>
  113. </div>
  114. <div class="rowLayout">
  115. <div class="descLayout">
  116. <div class="pad" data-jsfiddle="example2">
  117. <a name="specific"></a>
  118. <h2>Dropdown Menu with specific options</h2>
  119. <p>You can limit options available in the dropdown menu using dropdownMenu option as an array of strings.</p>
  120. <p>
  121. List of commands below are common for context menu and for dropdown menu.
  122. </p>
  123. <ul>
  124. <li><b>row_above</b> (designed for <a href="contextmenu.html">Context Menu</a>)</li>
  125. <li><b>row_below</b> (designed for <a href="contextmenu.html">Context Menu</a>)</li>
  126. <li><b>hsep1</b></li>
  127. <li><b>col_left</b> (designed for both menus)</li>
  128. <li><b>col_right</b> (designed for both menus)</li>
  129. <li><b>hsep2</b></li>
  130. <li><b>remove_row</b> (designed for <a href="contextmenu.html">Context Menu</a>)</li>
  131. <li><b>remove_col</b> (designed for both menus)</li>
  132. <li><b>hsep3</b></li>
  133. <li><b>undo</b> (designed for <a href="contextmenu.html">Context Menu</a>)</li>
  134. <li><b>redo</b> (designed for <a href="contextmenu.html">Context Menu</a>)</li>
  135. <li><b>make_read_only</b> (designed for both menus)</li>
  136. <li><b>alignment</b> (designed for both menus)</li>
  137. <li><b>clear_column</b> (designed for <a href="dropdownmenu.html">Dropdown Menu</a>)</li>
  138. <li><b>borders</b> (only with <a href="custom_borders.html">Custom Borders</a> turned on)</li>
  139. <li><b>commentsAddEdit</b>, <b>commentsRemove</b> (only with <a href="comments.html">Comments</a> turned on)</li>
  140. </ul>
  141. <div id="example2"></div>
  142. <p>
  143. <button name="dump" data-dump="#example2" data-instance="hot2" title="Prints current data source to Firebug/Chrome Dev Tools">Dump
  144. data to console
  145. </button>
  146. </p>
  147. </div>
  148. </div>
  149. <div class="codeLayout">
  150. <div class="pad">
  151. <div class="jsFiddle">
  152. <button class="jsFiddleLink" data-runfiddle="example2">Edit in jsFiddle</button>
  153. </div>
  154. <script data-jsfiddle="example2">
  155. var example2 = document.getElementById('example2');
  156. var settings2 = {
  157. data: getData(),
  158. startRows: 5,
  159. startCols: 5,
  160. rowHeaders: true,
  161. colHeaders: true, // If you use `dropdownMenu` option you must enable colHeaders
  162. minSpareRows: 1,
  163. dropdownMenu: ['col_left', 'col_right']
  164. };
  165. var hot2 = new Handsontable(example2, settings2);
  166. </script>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="rowLayout">
  171. <div class="descLayout">
  172. <div class="pad" data-jsfiddle="example3">
  173. <a name="custom"></a>
  174. <h2>Dropdown Menu with with fully custom configuration</h2>
  175. <p>For greatest configurability, you use dropdownMenu option as a configuration object as described in <a
  176. href="http://medialize.github.com/jQuery-contextMenu/docs.html">jQuery contextMenu documentation</a>.</p>
  177. <p>This example shows how to set <strong>custom text</strong>, how to <strong>disable</strong>
  178. "Remove row" and "Insert row above" for the first row and how to add your <strong>own option</strong>.</p>
  179. <div id="example3"></div>
  180. <p>
  181. <button name="dump" data-dump="#example3" data-instance="hot3" title="Prints current data source to Firebug/Chrome Dev Tools">Dump
  182. data to console
  183. </button>
  184. </p>
  185. </div>
  186. </div>
  187. <div class="codeLayout">
  188. <div class="pad">
  189. <div class="jsFiddle">
  190. <button class="jsFiddleLink" data-runfiddle="example3">Edit in jsFiddle</button>
  191. </div>
  192. <script data-jsfiddle="example3">
  193. var example3 = document.getElementById('example3');
  194. var settings3 = {
  195. data: getData(),
  196. startRows: 5,
  197. startCols: 5,
  198. rowHeaders: true,
  199. colHeaders: true, // If you use `dropdownMenu` option you must enable colHeaders
  200. minSpareRows: 1
  201. };
  202. var hot3 = new Handsontable(example3, settings3);
  203. hot3.updateSettings({
  204. dropdownMenu: {
  205. callback: function (key, options) {
  206. if (key === 'about') {
  207. setTimeout(function () {
  208. // timeout is used to make sure the menu collapsed before alert is shown
  209. alert("This is a dropdown menu with default and custom options mixed");
  210. }, 100);
  211. }
  212. },
  213. items: {
  214. "col_left": {
  215. disabled: function () {
  216. // if first column, disable this option
  217. return this.getSelected() && this.getSelected()[1] === 0;
  218. }
  219. },
  220. "col_right": {},
  221. "hsep1": "---------",
  222. "remove_col": {
  223. name: 'Remove this column, ok?',
  224. disabled: function () {
  225. // if first column, disable this option
  226. return this.getSelected() && this.getSelected()[1] === 0
  227. }
  228. },
  229. "hsep2": "---------",
  230. "about": {name: 'About this menu'}
  231. }
  232. }
  233. })
  234. </script>
  235. </div>
  236. </div>
  237. </div>
  238. <div class="footer-text">
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. <div id="outside-links-wrapper"></div>
  245. </body>
  246. </html>