date.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Date cell type - Handsontable</title>
  6. <!--
  7. Loading Handsontable
  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="Date cell type">
  29. <meta property="og:description"
  30. content="Date cell type uses the Pikaday Datepicker with Moment.js">
  31. <meta property="og:url" content="http://handsontable.com/demo/numeric.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/numeric.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. ["Mercedes", "A 160", "01/14/2006", 6999.9999],
  45. ["Citroen", "C4 Coupe", "12/01/2008", 8330],
  46. ["Audi", "A4 Avant", "11/19/2011", 33900],
  47. ["Opel", "Astra", "02/02/2004", 7000],
  48. ["BMW", "320i Coupe", "07/24/2011", 30500]
  49. ];
  50. }
  51. </script>
  52. </head>
  53. <body>
  54. <div class="wrapper">
  55. <div class="wrapper-row">
  56. <div id="global-menu-clone">
  57. <h1><a href="../index.html">Handsontable</a></h1>
  58. </div>
  59. <div id="container">
  60. <div class="columnLayout">
  61. <div class="rowLayout">
  62. <div class="descLayout">
  63. <div class="pad" data-jsfiddle="example1">
  64. <h2>Date cell type</h2>
  65. <p>To trigger the Date cell type, use the option <code>type: 'date'</code> in <code>columns</code> array
  66. or <code>cells</code> function.</p>
  67. <p>The Date cell uses <a href="https://github.com/dbushell/Pikaday">Pikaday datepicker</a> as
  68. the UI control. Pikaday uses <a href="https://github.com/moment/moment">Moment.js</a> as a date formatter.
  69. <p>Note that Date cell requires additional files in your <code>&lt;head&gt;</code>:
  70. <ul>
  71. <li><code>demo/js/moment/moment.js</code></li>
  72. <li><code>demo/js/pikaday/pikaday.js</code></li>
  73. <li><code>demo/js/pikaday/css/pikaday.css</code></li>
  74. </ul>
  75. <p>All data entered to the data-typed cells are validated agains the default date format (<code><a
  76. href="http://momentjs.com/docs/#/parsing/" target="_blank"
  77. title="Click here to find how to use different date format">DD/MM/YYYY</a></code>), unless another
  78. format is provided.</p>
  79. <p>If you enable the <code>correctFormat</code> config item, the dates will be automatically formatted to
  80. match the desired format.</p>
  81. <div id="example1"></div>
  82. <p>
  83. <button name="dump" data-instance="hot" data-dump="#example1"
  84. title="Prints current data source to Firebug/Chrome Dev Tools">
  85. Dump
  86. data to console
  87. </button>
  88. </p>
  89. </div>
  90. </div>
  91. <div class="codeLayout">
  92. <div class="pad">
  93. <div class="jsFiddle">
  94. <button class="jsFiddleLink" data-runfiddle="example1">Edit in jsFiddle</button>
  95. </div>
  96. <script data-jsfiddle="example1">
  97. var container = document.getElementById('example1'),
  98. hot;
  99. hot = new Handsontable(container, {
  100. data: getCarData(),
  101. startRows: 7,
  102. startCols: 4,
  103. colHeaders: ['Car', 'Model', 'Registration date', 'Price'],
  104. columnSorting: true,
  105. contextMenu: true,
  106. minSpareRows: 1,
  107. columns: [
  108. {
  109. type: 'autocomplete',
  110. source: ['Audi', 'BMW', 'Chrysler', 'Citroen', 'Mercedes', 'Nissan', 'Opel', 'Suzuki', 'Toyota', 'Volvo'],
  111. strict: false
  112. },
  113. {
  114. // 2nd cell is simple text, no special options here
  115. },
  116. {
  117. type: 'date',
  118. dateFormat: 'MM/DD/YYYY',
  119. correctFormat: true,
  120. defaultDate: '01/01/1900'
  121. },
  122. {
  123. type: 'numeric',
  124. format: '$ 0,0.00'
  125. }
  126. ]
  127. });
  128. </script>
  129. </div>
  130. </div>
  131. </div>
  132. <div class="footer-text">
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. <div id="outside-links-wrapper"></div>
  139. </body>
  140. </html>