checkbox.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Checkbox cell type - Handsontable</title>
  6. <!--
  7. Loading Handsontable (full distribution that includes all dependencies)
  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="Numeric cell type">
  29. <meta property="og:description"
  30. content="Numeric cell type uses Numeral.js as the formatting library.">
  31. <meta property="og:url" content="http://handsontable.com/demo/numeric.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/numeric.html">
  37. <!--
  38. Google Analytics for GitHub Page. Don't copy this to your project :)
  39. -->
  40. <script src="js/ga.js"></script>
  41. <script data-jsfiddle="common">
  42. function getCarData() {
  43. return [
  44. {car: "Mercedes A 160", year: 2006, available: true, comesInBlack: 'yes'},
  45. {car: "Citroen C4 Coupe", year: 2008, available: false, comesInBlack: 'yes'},
  46. {car: "Audi A4 Avant", year: 2011, available: true, comesInBlack: 'no'},
  47. {car: "Opel Astra", year: 2004, available: false, comesInBlack: 'yes'},
  48. {car: "BMW 320i Coupe", year: 2011, available: false, comesInBlack: 'no'}
  49. ];
  50. }
  51. </script>
  52. </head>
  53. <body>
  54. <div class="wrapper">
  55. <div class="wrapper-row">
  56. <div id="global-menu-clone">
  57. <h1><a href="../index.html">Handsontable</a></h1>
  58. </div>
  59. <div id="container">
  60. <div class="columnLayout">
  61. <div class="rowLayout">
  62. <div class="descLayout">
  63. <div class="pad" data-jsfiddle="example1">
  64. <h2>Checkbox cell type</h2>
  65. <p>If you have cells that contains only 2 possible values, you can use <code>checkbox</code> type.
  66. Data in such cells will be rendered as checkbox
  67. and can be easily changed by checking/unchecking the checkbox. </p>
  68. <p>Checking and unchecking can be performed using mouse or by pressing <kbd>SPACE</kbd>.
  69. You can change the state of multiple cells at once.
  70. Simply select cells you want to change and press <kbd>SPACE</kbd></p>
  71. <div id="example1"></div>
  72. <p>
  73. <button name="dump" data-dump="#example1" data-instance="hot1" title="Prints current data source to Firebug/Chrome Dev Tools">
  74. 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="example1">
  86. var example1 = document.getElementById('example1'),
  87. hot1;
  88. hot1 = new Handsontable(example1, {
  89. data: getCarData(),
  90. startRows: 7,
  91. startCols: 4,
  92. colHeaders: ['Car', 'Year', 'Available'],
  93. colWidths: [120, 50, 60],
  94. columnSorting: true,
  95. columns: [
  96. {
  97. data: 'car'
  98. // 1nd column is simple text, no special options here
  99. },
  100. {
  101. data: 'year',
  102. type: 'numeric'
  103. },
  104. {
  105. data: 'available',
  106. type: 'checkbox'
  107. }
  108. ]
  109. });
  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="lazy"></a>
  118. <h2>Check templates</h2>
  119. <p>If you want use other values than <code>true</code> and <code>false</code>,
  120. you have to provide this information using <code>checkedTemplate</code> and
  121. <code>uncheckedTemplate</code>. Handsontable will then update your data using appropriate template.
  122. </p>
  123. <div id="example2"></div>
  124. <p>
  125. <button name="dump" data-dump="#example2" data-instance="hot2" title="Prints current data source to Firebug/Chrome Dev Tools">
  126. Dump
  127. data to console
  128. </button>
  129. </p>
  130. </div>
  131. </div>
  132. <div class="codeLayout">
  133. <div class="pad">
  134. <div class="jsFiddle">
  135. <button class="jsFiddleLink" data-runfiddle="example2">Edit in jsFiddle</button>
  136. </div>
  137. <script data-jsfiddle="example2">
  138. var example2 = document.getElementById('example2');
  139. var hot2 = new Handsontable(example2,{
  140. data: getCarData(),
  141. startRows: 7,
  142. startCols: 4,
  143. colHeaders: ["Car", "Year", "Comes in black"],
  144. colWidths: [120, 50, 60],
  145. columnSorting: true,
  146. columns: [
  147. {
  148. data: "car"
  149. //1nd column is simple text, no special options here
  150. },
  151. {
  152. data: "year",
  153. type: 'numeric'
  154. },
  155. {
  156. data: "comesInBlack",
  157. type: "checkbox",
  158. checkedTemplate: 'yes',
  159. uncheckedTemplate: 'no'
  160. }
  161. ]
  162. });
  163. </script>
  164. </div>
  165. </div>
  166. </div>
  167. <div class="footer-text">
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. <div id="outside-links-wrapper"></div>
  174. </body>
  175. </html>