contextmenu.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <!doctype html>
  2. <html xmlns="http://www.w3.org/1999/html">
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Context 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>Context Menu</h2>
  54. <p>This page shows how to use and configure right-click context menu with Handsontable:</p>
  55. <ul>
  56. <li><a href="#default">context menu with default options</a></li>
  57. <li><a href="#specific">context menu with specific options</a></li>
  58. <li><a href="#custom">context 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>Context Menu with default options</h2>
  68. <p>Tu run the basic configuration of the Context Menu, just set the contextMenu option to true.</p>
  69. <p>From version 0.11, context menu also works for row and column headers. When the context menu for the row
  70. header is opened, the column options are disabled. Likewise, when the context menu for the column header is opened,
  71. the row options are disabled</p>
  72. <div id="example1"></div>
  73. <p>
  74. <button name="dump" data-dump="#example1" data-instance="hot1" title="Prints current data source to Firebug/Chrome Dev Tools">Dump
  75. data to console
  76. </button>
  77. </p>
  78. </div>
  79. </div>
  80. <div class="codeLayout">
  81. <div class="pad">
  82. <div class="jsFiddle">
  83. <button class="jsFiddleLink" data-runfiddle="example1">Edit in jsFiddle</button>
  84. </div>
  85. <script data-jsfiddle="common">
  86. function getData() {
  87. return [
  88. ['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
  89. ['2008', 10, 11, 12, 13],
  90. ['2009', 20, 11, 14, 13],
  91. ['2010', 30, 15, 12, 13]
  92. ];
  93. }
  94. </script>
  95. <script data-jsfiddle="example1">
  96. var example1 = document.getElementById('example1'),
  97. settings1,
  98. hot1;
  99. settings1 = {
  100. data: getData(),
  101. startRows: 5,
  102. startCols: 5,
  103. minRows: 5,
  104. minCols: 5,
  105. maxRows: 10,
  106. maxCols: 10,
  107. rowHeaders: true,
  108. colHeaders: true,
  109. minSpareRows: 1,
  110. contextMenu: true
  111. };
  112. hot1 = new Handsontable(example1, settings1);
  113. </script>
  114. </div>
  115. </div>
  116. </div>
  117. <div class="rowLayout">
  118. <div class="descLayout">
  119. <div class="pad" data-jsfiddle="example2">
  120. <a name="specific"></a>
  121. <h2>Context Menu with specific options</h2>
  122. <p>You can limit options available in the context menu using contextMenu option as an array of strings:</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. <li><b>freeze_column</b>, <b>unfreeze_column</b> (only with <a href="column_freeze.html">Column Freezing</a> turned on)</li>
  141. </ul>
  142. <div id="example2"></div>
  143. <p>
  144. <button name="dump" data-dump="#example2" data-instance="hot2" title="Prints current data source to Firebug/Chrome Dev Tools">Dump
  145. data to console
  146. </button>
  147. </p>
  148. </div>
  149. </div>
  150. <div class="codeLayout">
  151. <div class="pad">
  152. <div class="jsFiddle">
  153. <button class="jsFiddleLink" data-runfiddle="example2">Edit in jsFiddle</button>
  154. </div>
  155. <script data-jsfiddle="example2">
  156. var example2 = document.getElementById('example2');
  157. var settings2 = {
  158. data: getData(),
  159. startRows: 5,
  160. startCols: 5,
  161. rowHeaders: true,
  162. colHeaders: true,
  163. minSpareRows: 1,
  164. contextMenu: ['row_above', 'row_below', 'remove_row']
  165. };
  166. var hot2 = new Handsontable(example2, settings2);
  167. </script>
  168. </div>
  169. </div>
  170. </div>
  171. <div class="rowLayout">
  172. <div class="descLayout">
  173. <div class="pad" data-jsfiddle="example3">
  174. <a name="custom"></a>
  175. <h2>Context Menu with with fully custom configuration</h2>
  176. <p>For greatest configurability, you use contextMenu option as a configuration object as described in <a
  177. href="http://medialize.github.com/jQuery-contextMenu/docs.html">jQuery contextMenu documentation</a>.</p>
  178. <p>This example shows how to set <strong>custom text</strong>, how to <strong>disable</strong>
  179. "Remove row" and "Insert row above" for the first row and how to add your <strong>own option</strong>.</p>
  180. <div id="example3"></div>
  181. <p>
  182. <button name="dump" data-dump="#example3" data-instance="hot3" title="Prints current data source to Firebug/Chrome Dev Tools">Dump
  183. data to console
  184. </button>
  185. </p>
  186. </div>
  187. </div>
  188. <div class="codeLayout">
  189. <div class="pad">
  190. <div class="jsFiddle">
  191. <button class="jsFiddleLink" data-runfiddle="example3">Edit in jsFiddle</button>
  192. </div>
  193. <script data-jsfiddle="example3">
  194. var example3 = document.getElementById('example3');
  195. var settings3 = {
  196. data: getData(),
  197. startRows: 5,
  198. startCols: 5,
  199. rowHeaders: true,
  200. colHeaders: true,
  201. minSpareRows: 1
  202. };
  203. var hot3 = new Handsontable(example3,settings3);
  204. hot3.updateSettings({
  205. contextMenu: {
  206. callback: function (key, options) {
  207. if (key === 'about') {
  208. setTimeout(function () {
  209. //timeout is used to make sure the menu collapsed before alert is shown
  210. alert("This is a context menu with default and custom options mixed");
  211. }, 100);
  212. }
  213. },
  214. items: {
  215. "row_above": {
  216. disabled: function () {
  217. //if first row, disable this option
  218. return (hot3.getSelected() && hot3.getSelected()[0]===0)
  219. }
  220. },
  221. "row_below": {},
  222. "hsep1": "---------",
  223. "remove_row": {
  224. name: 'Remove this row, ok?',
  225. disabled: function () {
  226. //if first row, disable this option
  227. return (hot3.getSelected() && hot3.getSelected()[0] === 0)
  228. }
  229. },
  230. "hsep2": "---------",
  231. "about": {name: 'About this menu'}
  232. }
  233. }
  234. })
  235. </script>
  236. </div>
  237. </div>
  238. </div>
  239. <div class="footer-text">
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. <div id="outside-links-wrapper"></div>
  246. </body>
  247. </html>