handsontable_basic.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Handsontable - Excel-like tables with extensive funtionality
  4. *
  5. * Demo JS code for handsontable_basic.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var HotBasic = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Basic HOT examples
  15. var _componentHotBasic = function() {
  16. if (typeof Handsontable == 'undefined') {
  17. console.warn('Warning - handsontable.min.js is not loaded.');
  18. return;
  19. }
  20. // Basic configuration
  21. // ------------------------------
  22. // Add data for all examples
  23. var car_data = [
  24. {car: "Mercedes", model: "GL500", year: 2009, color: "blue", price: 32500},
  25. {car: "Chevrolet", model: "Camaro", year: 2012, color: "red", price: 42400},
  26. {car: "Dodge", model: "Charger", year: 2011, color: "white", price: 24900},
  27. {car: "Hummer", model: "H3", year: 2014, color: "black", price: 54000},
  28. {car: "Chevrolet", model: "Tahoe", year: 2009, color: "purple", price: 29300},
  29. {car: "Toyota", model: "Land Cruiser", year: 2007, color: "lime", price: 54500},
  30. {car: "Nissan", model: "GTR", year: 2009, color: "cyan", price: 44900},
  31. {car: "Porsche", model: "Cayenne", year: 2012, color: "yellow", price: 35000},
  32. {car: "Volkswagen", model: "Touareg", year: 2010, color: "crimson", price: 41000},
  33. {car: "BMW", model: "X5", year: 2010, color: "orange", price: 48800},
  34. {car: "Audi", model: "Q7", year: 2009, color: "green", price: 21000},
  35. {car: "Cadillac", model: "Escalade", year: 2012, color: "silver", price: 63900}
  36. ];
  37. // Define element
  38. var hot_basic = document.getElementById('hot_basic');
  39. // Initialize with options
  40. var hot_basic_init = new Handsontable(hot_basic, {
  41. data: car_data,
  42. stretchH: 'all'
  43. });
  44. $('.sidebar-control').on('click', function() {
  45. hot_basic_init.render();
  46. })
  47. // Column headers
  48. // ------------------------------
  49. // Define element
  50. var hot_col_headers = document.getElementById('hot_col_headers');
  51. // Initialize with options
  52. var hot_col_headers_init = new Handsontable(hot_col_headers, {
  53. data: car_data,
  54. colHeaders: true,
  55. stretchH: 'all'
  56. });
  57. // Row headers
  58. // ------------------------------
  59. // Define element
  60. var hot_row_headers = document.getElementById('hot_row_headers');
  61. // Initialize with options
  62. var hot_row_headers_init = new Handsontable(hot_row_headers, {
  63. data: car_data,
  64. colHeaders: true,
  65. rowHeaders: true,
  66. stretchH: 'all'
  67. });
  68. // Custom headers text
  69. // ------------------------------
  70. // Define element
  71. var hot_headers = document.getElementById('hot_headers');
  72. // Initialize with options
  73. var hot_headers_init = new Handsontable(hot_headers, {
  74. data: car_data,
  75. rowHeaders: true,
  76. colHeaders: ['Brand', 'Model', 'Year', 'Color', 'Price'],
  77. stretchH: 'all'
  78. });
  79. // Comments
  80. // ------------------------------
  81. // Define element
  82. var hot_comments = document.getElementById('hot_comments');
  83. // Init with options
  84. var hot_comments_init = new Handsontable(hot_comments, {
  85. data: car_data,
  86. rowHeaders: true,
  87. colHeaders: true,
  88. stretchH: 'all',
  89. comments: true,
  90. cell: [
  91. {row: 1, col: 1, comment: {value: 'The most nice looking muscle car'}},
  92. {row: 2, col: 2, comment: {value: 'Another comment'}}
  93. ]
  94. });
  95. // Custom borders
  96. // ------------------------------
  97. // Add data
  98. var hot_borders_data = Handsontable.helper.createSpreadsheetData(40, 10);
  99. // Define element
  100. var hot_borders = document.getElementById('hot_borders');
  101. // Init with options
  102. hot_borders_init = Handsontable(hot_borders, {
  103. data: hot_borders_data,
  104. rowHeaders: true,
  105. stretchH: 'all',
  106. fixedColumnsLeft: 2,
  107. fixedRowsTop: 2,
  108. colHeaders: true,
  109. customBorders: [
  110. {
  111. range: {
  112. from: {
  113. row: 1,
  114. col: 1
  115. },
  116. to: {
  117. row: 3,
  118. col: 4
  119. }
  120. },
  121. top: {
  122. width: 2,
  123. color: '#5292F7'
  124. },
  125. left: {
  126. width: 2,
  127. color: 'orange'
  128. },
  129. bottom: {
  130. width: 2,
  131. color: 'red'
  132. },
  133. right: {
  134. width: 2,
  135. color: 'magenta'
  136. }
  137. },
  138. {
  139. row: 2,
  140. col: 2,
  141. left: {
  142. width: 2,
  143. color: 'red'
  144. },
  145. right: {
  146. width: 1,
  147. color: 'green'
  148. }
  149. }
  150. ]
  151. });
  152. };
  153. //
  154. // Return objects assigned to module
  155. //
  156. return {
  157. init: function() {
  158. _componentHotBasic();
  159. }
  160. }
  161. }();
  162. // Initialize module
  163. // ------------------------------
  164. document.addEventListener('DOMContentLoaded', function() {
  165. HotBasic.init();
  166. });