renderers.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Cell types - 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="Cell types">
  29. <meta property="og:description"
  30. content="This example shows the default renderers and editors available in Handsontable.">
  31. <meta property="og:url" content="http://handsontable.com/demo/renderers.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/renderers.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>Cell types</h2>
  54. <p>This page is an introduction to Handsontable cell types:</p>
  55. <ul>
  56. <li><a href="#preview">Preview of built-in and custom cell types</a></li>
  57. <li><a href="#anatomy">Anatomy of a cell type</a></li>
  58. </ul>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="rowLayout">
  63. <div class="descLayout">
  64. <div class="pad" data-jsfiddle="example1">
  65. <a name="preview"></a>
  66. <h2>Preview of built-in and custom cell types</h2>
  67. <p>The below example shows all built-in cell types (in other words, combinations of cell renderers and
  68. editors)
  69. available in Handsontable:</p>
  70. <ul>
  71. <li>text</li>
  72. <li><a href="numeric.html">numeric</a></li>
  73. <li>checkbox</li>
  74. <li><a href="date.html">date</a></li>
  75. <li><a href="autocomplete.html">autocomplete</a></li>
  76. </ul>
  77. <p>The same example also shows the declaration of custom cell renderers, namely <code>yellowRenderer</code>
  78. and
  79. <code>greenRenderer</code>.
  80. </p>
  81. <div id="example1"></div>
  82. <p>
  83. <button name="dump" data-instance="hot1" data-dump="#example1" title="Prints current data source to Firebug/Chrome Dev Tools">
  84. Dump
  85. data to console
  86. </button>
  87. </p>
  88. </div>
  89. </div>
  90. <div class="codeLayout">
  91. <div class="pad">
  92. <div class="jsFiddle">
  93. <button class="jsFiddleLink" data-runfiddle="example1">Edit in jsFiddle</button>
  94. </div>
  95. <script data-jsfiddle="example1">
  96. var data = [
  97. {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01'},
  98. {id: 2, name: 'John', isActive: false, color: 'black', date: null},
  99. {id: 3, name: 'Al', isActive: true, color: 'red', date: null},
  100. {id: 4, name: 'Ben', isActive: false, color: 'blue', date: null}
  101. ],
  102. container = document.getElementById('example1'),
  103. hot1,
  104. yellowRenderer,
  105. greenRenderer;
  106. yellowRenderer = function(instance, td, row, col, prop, value, cellProperties) {
  107. Handsontable.renderers.TextRenderer.apply(this, arguments);
  108. td.style.backgroundColor = 'yellow';
  109. };
  110. greenRenderer = function(instance, td, row, col, prop, value, cellProperties) {
  111. Handsontable.renderers.TextRenderer.apply(this, arguments);
  112. td.style.backgroundColor = 'green';
  113. };
  114. hot1 = new Handsontable(container, {
  115. data: data,
  116. startRows: 5,
  117. colHeaders: true,
  118. minSpareRows: 1,
  119. columns: [
  120. {data: "id", type: 'text'},
  121. // 'text' is default, you don't actually have to declare it
  122. {data: "name", renderer: yellowRenderer},
  123. // use default 'text' cell type but overwrite its renderer with yellowRenderer
  124. {data: "isActive", type: 'checkbox'},
  125. {data: "date", type: 'date', dateFormat: 'YYYY-MM-DD'},
  126. {data: "color",
  127. type: 'autocomplete',
  128. source: ["yellow", "red", "orange", "green", "blue", "gray", "black", "white"]
  129. }
  130. ],
  131. cell: [
  132. {row: 1, col: 0, renderer: greenRenderer}
  133. ],
  134. cells: function (row, col, prop) {
  135. if (row === 0 && col === 0) {
  136. this.renderer = greenRenderer;
  137. }
  138. }
  139. });
  140. </script>
  141. </div>
  142. </div>
  143. </div>
  144. <div class="rowLayout">
  145. <div class="descLayout">
  146. <div class="pad">
  147. <a name="anatomy"></a>
  148. <h2>Anatomy of a cell type</h2>
  149. <p>A cell type is a predefined set of cell properties. Cell type defines what <strong>renderer</strong>
  150. and <strong>editor</strong> should be used for a cell. They can also define any different cell property that
  151. will be assumed for each matching cell.</p>
  152. <p>For example writing:</p>
  153. <pre class="javascript"><code>
  154. columns: [{
  155. type: 'text'
  156. }]
  157. </code></pre>
  158. <p>Equals:</p>
  159. <pre class="javascript"><code>
  160. columns: [{
  161. renderer: Handsontable.renderers.TextRenderer,
  162. editor: Handsontable.editors.TextEditor
  163. }]
  164. </code></pre>
  165. This mapping is defined in file <a
  166. href="https://github.com/handsontable/handsontable/blob/master/src/cellTypes.js">src/cellTypes.js</a>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="footer-text">
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. <div id="outside-links-wrapper"></div>
  177. </body>
  178. </html>