sorting.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Column sorting - 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="Column sorting">
  29. <meta property="og:description"
  30. content="Click on a column header to sort.">
  31. <meta property="og:url" content="http://handsontable.com/demo/sorting.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/sorting.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 createBigData() {
  43. return [
  44. [1, "George Washington", "http://en.wikipedia.org/wiki/George_Washington", "30/04/1789", "4/03/1797", "Independent ", "Virginia"],
  45. [2, "John Adams", "http://en.wikipedia.org/wiki/John_Adams", "4/03/1797", "4/03/1801", "Federalist ", "Massachusetts"],
  46. [3, "Thomas Jefferson", "http://en.wikipedia.org/wiki/Thomas_Jefferson", "4/03/1801", "4/03/1809", "Democratic-Republican ", "Virginia"],
  47. [4, "James Madison", "http://en.wikipedia.org/wiki/James_Madison", "4/03/1809", "4/03/1817", "Democratic-Republican ", "Virginia"],
  48. [5, "James Monroe", "http://en.wikipedia.org/wiki/James_Monroe", "4/03/1817", "4/03/1825", "Democratic-Republican ", "Virginia"],
  49. [6, "John Quincy Adams", "http://en.wikipedia.org/wiki/John_Quincy_Adams", "4/03/1825", "4/03/1829", "Democratic-Republican/National Republican ", "Massachusetts"],
  50. [7, "Andrew Jackson", "http://en.wikipedia.org/wiki/Andrew_Jackson", "4/03/1829", "4/03/1837", "Democratic ", "Tennessee"],
  51. [8, "Martin Van Buren", "http://en.wikipedia.org/wiki/Martin_Van_Buren", "4/03/1837", "4/03/1841", "Democratic ", "New York"],
  52. [9, "William Henry Harrison", "http://en.wikipedia.org/wiki/William_Henry_Harrison", "4/03/1841", "4/04/1841", "Whig", "Ohio"],
  53. [10, "John Tyler", "http://en.wikipedia.org/wiki/John_Tyler", "4/04/1841", "4/03/1845", "Whig", "Virginia"],
  54. [11, "James K. Polk", "http://en.wikipedia.org/wiki/James_K._Polk", "4/03/1845", "4/03/1849", "Democratic ", "Tennessee"],
  55. [12, "Zachary Taylor", "http://en.wikipedia.org/wiki/Zachary_Taylor", "4/03/1849", "9/07/1850", "Whig", "Louisiana"],
  56. [13, "Millard Fillmore", "http://en.wikipedia.org/wiki/Millard_Fillmore", "9/07/1850", "4/03/1853", "Whig", "New York"],
  57. [14, "Franklin Pierce", "http://en.wikipedia.org/wiki/Franklin_Pierce", "4/03/1853", "4/03/1857", "Democratic ", "New Hampshire"],
  58. [15, "James Buchanan", "http://en.wikipedia.org/wiki/James_Buchanan", "4/03/1857", "4/03/1861", "Democratic ", "Pennsylvania"],
  59. [16, "Abraham Lincoln", "http://en.wikipedia.org/wiki/Abraham_Lincoln", "4/03/1861", "15/04/1865", "Republican/National Union", "Illinois"],
  60. [17, "Andrew Johnson", "http://en.wikipedia.org/wiki/Andrew_Johnson", "15/04/1865", "4/03/1869", "Democratic/National Union", "Tennessee"],
  61. [18, "Ulysses S. Grant", "http://en.wikipedia.org/wiki/Ulysses_S._Grant", "4/03/1869", "4/03/1877", "Republican ", "Ohio"],
  62. [19, "Rutherford B. Hayes", "http://en.wikipedia.org/wiki/Rutherford_B._Hayes", "4/03/1877", "4/03/1881", "Republican ", "Ohio"],
  63. [20, "James A. Garfield", "http://en.wikipedia.org/wiki/James_A._Garfield", "4/03/1881", "19/09/1881", "Republican ", "Ohio"],
  64. [21, "Chester A. Arthur", "http://en.wikipedia.org/wiki/Chester_A._Arthur", "19/09/1881", "4/03/1885", "Republican ", "New York"],
  65. [22, "Grover Cleveland", "http://en.wikipedia.org/wiki/Grover_Cleveland", "4/03/1885", "4/03/1889", "Democratic ", "New York"],
  66. [23, "Benjamin Harrison", "http://en.wikipedia.org/wiki/Benjamin_Harrison", "4/03/1889", "4/03/1893", "Republican ", "Indiana"],
  67. [24, "Grover Cleveland (2nd term)", "http://en.wikipedia.org/wiki/Grover_Cleveland", "4/03/1893", "4/03/1897", "Democratic ", "New York"],
  68. [25, "William McKinley", "http://en.wikipedia.org/wiki/William_McKinley", "4/03/1897", "14/9/1901", "Republican ", "Ohio"],
  69. [26, "Theodore Roosevelt", "http://en.wikipedia.org/wiki/Theodore_Roosevelt", "14/9/1901", "04/03/09", "Republican ", "New York"],
  70. [27, "William Howard Taft", "http://en.wikipedia.org/wiki/William_Howard_Taft", "04/03/09", "04/03/13", "Republican ", "Ohio"],
  71. [28, "Woodrow Wilson", "http://en.wikipedia.org/wiki/Woodrow_Wilson", "04/03/13", "04/03/21", "Democratic ", "New Jersey"],
  72. [29, "Warren G. Harding", "http://en.wikipedia.org/wiki/Warren_G._Harding", "04/03/21", "02/08/23", "Republican ", "Ohio"],
  73. [30, "Calvin Coolidge", "http://en.wikipedia.org/wiki/Calvin_Coolidge", "02/08/23", "04/03/29", "Republican ", "Massachusetts"],
  74. [31, "Herbert Hoover", "http://en.wikipedia.org/wiki/Herbert_Hoover", "04/03/29", "04/03/33", "Republican ", "Iowa"],
  75. [32, "Franklin D. Roosevelt", "http://en.wikipedia.org/wiki/Franklin_D._Roosevelt", "04/03/33", "12/04/45", "Democratic", "New York"],
  76. [33, "Harry S. Truman", "http://en.wikipedia.org/wiki/Harry_S._Truman", "12/04/45", "20/01/53", "Democratic", "Missouri"],
  77. [34, "Dwight D. Eisenhower", "http://en.wikipedia.org/wiki/Dwight_D._Eisenhower", "20/01/53", "20/01/61", "Republican ", "Texas"],
  78. [35, "John F. Kennedy", "http://en.wikipedia.org/wiki/John_F._Kennedy", "20/01/61", "22/11/63", "Democratic", "Massachusetts"],
  79. [36, "Lyndon B. Johnson", "http://en.wikipedia.org/wiki/Lyndon_B._Johnson", "22/11/63", "20/01/69", "Democratic", "Texas"],
  80. [37, "Richard Nixon", "http://en.wikipedia.org/wiki/Richard_Nixon", "20/01/69", "09/08/74", "Republican", "California"],
  81. [38, "Gerald Ford", "http://en.wikipedia.org/wiki/Gerald_Ford", "09/08/74", "20/01/77", "Republican", "Michigan"],
  82. [39, "Jimmy Carter", "http://en.wikipedia.org/wiki/Jimmy_Carter", "20/01/77", "20/01/81", "Democratic ", "Georgia"],
  83. [40, "Ronald Reagan", "http://en.wikipedia.org/wiki/Ronald_Reagan", "20/01/81", "20/01/89", "Republican ", "California"],
  84. [41, "George H. W. Bush", "http://en.wikipedia.org/wiki/George_H._W._Bush", "20/01/89", "20/01/93", "Republican ", "Texas"],
  85. [42, "Bill Clinton", "http://en.wikipedia.org/wiki/Bill_Clinton", "20/01/93", "20/01/01", "Democratic ", "Arkansas"],
  86. [43, "George W. Bush", "http://en.wikipedia.org/wiki/George_W._Bush", "20/01/01", "20/01/09", "Republican ", "Texas"],
  87. [44, "Barack Obama", "http://en.wikipedia.org/wiki/Barack_Obama", "20/01/09", "Incumbent ", " Democratic ", "Illinois"]
  88. ]
  89. }
  90. </script>
  91. </head>
  92. <body>
  93. <div class="wrapper">
  94. <div class="wrapper-row">
  95. <div id="global-menu-clone">
  96. <h1><a href="../index.html">Handsontable</a></h1>
  97. </div>
  98. <div id="container">
  99. <div class="columnLayout">
  100. <div class="rowLayout">
  101. <div class="descLayout">
  102. <div class="pad" data-jsfiddle="example1">
  103. <h2>Column sorting</h2>
  104. <p>Click on a column header to sort.</p>
  105. <p>Only the table view is sorted. The data source remains in the original order.</p>
  106. <p>For an in depth documentation of column sorting plugin see the
  107. <a href="https://github.com/handsontable/handsontable/wiki/Understanding-column-sorting-plugin">Understanding column sorting plugin</a> wiki page.
  108. </p>
  109. <div class="state-loaded alert">State of the table has been restored. <button class="mini reset-state">Reset table state</button></div>
  110. <p><strong>Presidents of USA</strong></p>
  111. <div id="example1" style="width: 600px; height: 300px; overflow: hidden;"></div>
  112. <p>
  113. <button name="dump" data-dump="#example1" data-instance="hot" title="Prints current data source to Firebug/Chrome Dev Tools">
  114. Dump
  115. data to console
  116. </button>
  117. </p>
  118. </div>
  119. </div>
  120. <div class="codeLayout">
  121. <div class="pad">
  122. <div class="jsFiddle">
  123. <button class="jsFiddleLink" data-runfiddle="example1">Edit in jsFiddle</button>
  124. </div>
  125. <script data-jsfiddle="example1">
  126. var container = document.getElementById('example1'),
  127. storedData = {},
  128. savedKeys,
  129. resetState,
  130. stateLoaded,
  131. hot;
  132. hot = new Handsontable(container, {
  133. data: createBigData(),
  134. rowHeaders: true,
  135. colHeaders: true,
  136. colWidths: [45, 200, 110, 280],
  137. columnSorting: true,
  138. columns: [
  139. {data: 0},
  140. {data: 1},
  141. {data: 6},
  142. {data: 5}
  143. ],
  144. manualColumnMove: true,
  145. manualColumnResize: true,
  146. manualRowMove: true,
  147. manualRowResize: true,
  148. minSpareRows: 1,
  149. contextMenu: true,
  150. persistentState: true
  151. });
  152. resetState = document.querySelector('.reset-state');
  153. stateLoaded = document.querySelector('.state-loaded');
  154. Handsontable.dom.addEvent(resetState, 'click', function() {
  155. hot.runHooks('persistentStateReset');
  156. hot.updateSettings({
  157. columnSorting: true,
  158. manualColumnMove:true,
  159. manualColumnResize: true
  160. });
  161. stateLoaded.style.display = 'none';
  162. hot.render();
  163. });
  164. // `storedData` will be modified by reference
  165. hot.runHooks('persistentStateLoad', '_persistentStateKeys', storedData);
  166. savedKeys = storedData.value;
  167. if (savedKeys && savedKeys.length > 0){
  168. stateLoaded.style.display = 'block';
  169. }
  170. </script>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="footer-text">
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. </div>
  180. <div id="outside-links-wrapper"></div>
  181. </body>
  182. </html>