readonly.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Read-only cells - 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="Read-only cells">
  29. <meta property="og:description"
  30. content="This example shows how to set up read-only cells">
  31. <meta property="og:url" content="http://handsontable.com/demo/autocomplete.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/autocomplete.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: 'Nissan', year: 2009, chassis: 'black', bumper: 'black'},
  45. {car: 'Nissan', year: 2006, chassis: 'blue', bumper: 'blue'},
  46. {car: 'Chrysler', year: 2004, chassis: 'yellow', bumper: 'black'},
  47. {car: 'Volvo', year: 2012, chassis: 'white', bumper: 'gray'}
  48. ];
  49. }
  50. </script>
  51. </head>
  52. <body>
  53. <div class="wrapper">
  54. <div class="wrapper-row">
  55. <div id="global-menu-clone">
  56. <h1><a href="../index.html">Handsontable</a></h1>
  57. </div>
  58. <div id="container">
  59. <div class="columnLayout">
  60. <div class="rowLayout">
  61. <div class="descLayout">
  62. <div class="pad">
  63. <h2>Read-only cells</h2>
  64. <p>This page shows ways to configure columns or cells to be read only:</p>
  65. <ul>
  66. <li><a href="#columns">Read-only columns</a></li>
  67. <li><a href="#cells">Read-only specific cells</a></li>
  68. </ul>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="rowLayout">
  73. <div class="descLayout">
  74. <div class="pad" data-jsfiddle="example1">
  75. <a name="columns"></a>
  76. <h2>Read-only columns</h2>
  77. <p>In many usage cases, you will need to configure a certain column to be read only. This column will be
  78. available for keyboard navigation and CTRL+C. Only editing and pasting data will be disabled.</p>
  79. <p>To make a column read-only, declare it in the <code>columns</code> setting. You can also define a special
  80. renderer function that will dim the read-only values.</p>
  81. <div id="example1"></div>
  82. <p>
  83. <button name="dump" data-dump="#example1" data-instance="hot1" title="Prints current data source to Firebug/Chrome Dev Tools">
  84. Dump data to console
  85. </button>
  86. </p>
  87. </div>
  88. </div>
  89. <div class="codeLayout">
  90. <div class="pad">
  91. <div class="jsFiddle">
  92. <button class="jsFiddleLink" data-runfiddle="example1">Edit in jsFiddle</button>
  93. </div>
  94. <script data-jsfiddle="example1">
  95. var container1 = document.getElementById('example1'),
  96. hot1;
  97. hot1 = new Handsontable(container1, {
  98. data: getCarData(),
  99. minSpareRows: 1,
  100. colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
  101. columns: [
  102. {
  103. data: 'car',
  104. readOnly: true
  105. },
  106. {
  107. data: 'year'
  108. },
  109. {
  110. data: 'chassis'
  111. },
  112. {
  113. data: 'bumper'
  114. }
  115. ]
  116. });
  117. </script>
  118. </div>
  119. </div>
  120. </div>
  121. <div class="rowLayout">
  122. <div class="descLayout">
  123. <div class="pad" data-jsfiddle="example2">
  124. <a name="cells"></a>
  125. <h2>Read-only specific cells</h2>
  126. <p>This example makes cells that contain the word "Nissan" read only.</p>
  127. <p>It forces all cells to be rendered by <code>myReadonlyRenderer</code>, which will decide wheather a cell is
  128. really read only by checking its <code>readOnly</code> property.</p>
  129. <div id="example2"></div>
  130. <p>
  131. <button name="dump" data-dump="#example2" data-instance="hot2" title="Prints current data source to Firebug/Chrome Dev Tools">
  132. Dump data to console
  133. </button>
  134. </p>
  135. </div>
  136. </div>
  137. <div class="codeLayout">
  138. <div class="pad">
  139. <div class="jsFiddle">
  140. <button class="jsFiddleLink" data-runfiddle="example2">Edit in jsFiddle</button>
  141. </div>
  142. <script data-jsfiddle="example2">
  143. var container2 = document.getElementById('example2'),
  144. hot2;
  145. hot2 = new Handsontable(container2, {
  146. data: getCarData(),
  147. minSpareRows: 1,
  148. colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color']
  149. });
  150. hot2.updateSettings({
  151. cells: function (row, col, prop) {
  152. var cellProperties = {};
  153. if (hot2.getData()[row][prop] === 'Nissan') {
  154. cellProperties.readOnly = true;
  155. }
  156. return cellProperties;
  157. }
  158. })
  159. </script>
  160. </div>
  161. </div>
  162. </div>
  163. <div class="footer-text">
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. <div id="outside-links-wrapper"></div>
  170. </body>
  171. </html>