handsontable_cols.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Handsontable - Excel-like tables with extensive funtionality
  4. *
  5. * Demo JS code for handsontable_cols.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var HotColumns = function() {
  11. //
  12. // Setup module components
  13. //
  14. // HOT columns examples
  15. var _componentHotColumns = function() {
  16. if (typeof Handsontable == 'undefined') {
  17. console.warn('Warning - handsontable.min.js is not loaded.');
  18. return;
  19. }
  20. // Fixed columns and rows
  21. // ------------------------------
  22. // Generate sample data
  23. var hot_fixed_data = Handsontable.helper.createSpreadsheetData(40, 40);
  24. // Define element
  25. var hot_fixed = document.getElementById('hot_fixed');
  26. // Initialize with options
  27. var hot_fixed_init = new Handsontable(hot_fixed, {
  28. data: hot_fixed_data,
  29. rowHeaders: true,
  30. colHeaders: true,
  31. stretchH: 'all',
  32. fixedRowsTop: 2,
  33. fixedColumnsLeft: 2
  34. });
  35. // Scrolling
  36. // ------------------------------
  37. // Generate sample data
  38. var hot_scroll_data = Handsontable.helper.createSpreadsheetData(250, 40);
  39. // Define element
  40. var hot_scroll = document.getElementById('hot_scroll');
  41. // Initialize with options
  42. var hot_scroll_init = new Handsontable(hot_scroll,{
  43. data: hot_scroll_data,
  44. stretchH: 'all',
  45. rowHeaders: true,
  46. colHeaders: true
  47. });
  48. // Columns freezing
  49. // ------------------------------
  50. // Generate sample data
  51. var hot_freezing_data = Handsontable.helper.createSpreadsheetData(40, 40);
  52. // Define element
  53. var hot_freezing = document.getElementById('hot_freezing');
  54. // Initialize with options
  55. var hot_freezing_init = new Handsontable(hot_freezing, {
  56. data: hot_freezing_data,
  57. rowHeaders: true,
  58. colHeaders: true,
  59. stretchH: 'all',
  60. fixedColumnsLeft: 2,
  61. contextMenu: ['row_above', 'row_below', '---------', 'freeze_column'],
  62. manualColumnFreeze: true
  63. });
  64. // Columns and rows moving
  65. // ------------------------------
  66. // Add data for multiple examples
  67. var car_data = [
  68. {car: "Mercedes", model: "GL500", year: 2009, color: "blue", price: 32500},
  69. {car: "Chevrolet", model: "Camaro", year: 2012, color: "red", price: 42400},
  70. {car: "Dodge", model: "Charger", year: 2011, color: "white", price: 24900},
  71. {car: "Hummer", model: "H3", year: 2014, color: "black", price: 54000},
  72. {car: "Chevrolet", model: "Tahoe", year: 2009, color: "purple", price: 29300},
  73. {car: "Toyota", model: "Land Cruiser", year: 2007, color: "lime", price: 54500},
  74. {car: "Nissan", model: "GTR", year: 2009, color: "cyan", price: 44900},
  75. {car: "Porsche", model: "Cayenne", year: 2012, color: "yellow", price: 35000},
  76. {car: "Volkswagen", model: "Touareg", year: 2010, color: "crimson", price: 41000},
  77. {car: "BMW", model: "X5", year: 2010, color: "orange", price: 48800},
  78. {car: "Audi", model: "Q7", year: 2009, color: "green", price: 21000},
  79. {car: "Cadillac", model: "Escalade", year: 2012, color: "silver", price: 63900}
  80. ];
  81. // Define element
  82. var hot_moving = document.getElementById('hot_moving');
  83. // Initialize with options
  84. var hot_moving_init = new Handsontable(hot_moving, {
  85. data: car_data,
  86. rowHeaders: true,
  87. colHeaders: ['Brand', 'Model', 'Year', 'Color', 'Price'],
  88. stretchH: 'all',
  89. manualColumnMove: true,
  90. manualRowMove: true
  91. });
  92. // Columns stretching
  93. // ------------------------------
  94. // Define element
  95. var hot_stretch = document.getElementById('hot_stretch');
  96. // Initialize with options
  97. var hot_stretch_init = new Handsontable(hot_stretch, {
  98. data: car_data,
  99. colWidths: [150, 150, 100, 120],
  100. rowHeaders: true,
  101. colHeaders: ['Brand', 'Model', 'Year', 'Color', 'Price'],
  102. stretchH: 'last'
  103. });
  104. // Resize
  105. // ------------------------------
  106. // Add data
  107. var hot_resize_data = Handsontable.helper.createSpreadsheetData(10, 10);
  108. // Initialize with options
  109. var hot_resize_init = new Handsontable(hot_resize, {
  110. data: car_data,
  111. rowHeaders: true,
  112. colHeaders: ['Brand', 'Model', 'Year', 'Color', 'Price'],
  113. stretchH: 'all',
  114. colWidths: [55, 80, 80, 80, 80, 80, 80],
  115. rowHeights: [50, 40, 100],
  116. manualColumnResize: true,
  117. manualRowResize: true
  118. });
  119. };
  120. //
  121. // Return objects assigned to module
  122. //
  123. return {
  124. init: function() {
  125. _componentHotColumns();
  126. }
  127. }
  128. }();
  129. // Initialize module
  130. // ------------------------------
  131. document.addEventListener('DOMContentLoaded', function() {
  132. HotColumns.init();
  133. });