Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I made up a fiddle, I illustrate how it works; I hope I undestand correctly what are you asking.</p> <p>The project use a (I ca'nt set it hidden...) input field and attach to it a jQuery <a href="http://keith-wood.name/datepick.html" rel="nofollow"><code>datepick</code></a>; it's not used a standard jQuery UI datepicker because it isn't support the range selection.</p> <p>When you add a column it will be added a class <code>canDatePicker</code> to every cell of the column, this class tells that can be "attached" a datepicker to the cell. Using a contenteditable for every cell I managed the current focused cell by adding a class <code>focused</code>, so I know the current cell. When you attach a datepicker to the cell it's added a class <code>hasDatePicker</code> to the cell for the future new clicks on the cell.</p> <p>When you select the range from the datepicker the range is set on the text of the cell. If you click again on the cell the datepicker is opened with the cell range previously selected.</p> <p>Let me know if you need more explaination of the code.</p> <p>Code:</p> <pre><code>$(document).ready(function () { $('#datepicker').datepick({ rangeSelect: true, onClose: function () { var dates = $('#datepicker').datepick('getDate'); var value = ''; for (var i = 0; i &lt; dates.length; i++) { value += (i == 0 ? '' : ' - ') + $.datepick.formatDate(dates[i]); } $('.focused').html(value); } }); $(document).on('focus', '.hasDatePicker', function (e) { var dates = $(this).text().split(' - '); $("#datepicker").datepick('setDate', dates); $("#datepicker").datepick('show') }); $(document).on('focus', 'td', function (e) { $("td").removeClass('focused'); $(e.target).addClass('focused'); }); var $cell = $('&lt;td&gt;', { 'class': 'td', 'align': 'center', 'contenteditable': '', 'text': 'Content' }); var $header = $('&lt;th&gt;', { 'class': 'th', 'contenteditable': '', 'text': 'Heading' }); $('#addcolumn').click(function () { $header.clone().appendTo('thead tr'); $cell.clone().appendTo('tbody tr'); $('table&gt;tbody&gt;tr&gt;td:nth-child(n+4)').addClass('canDatePicker'); }); $('#addrow').click(function () { var $row = $('&lt;tr&gt;'); $('th').each(function () { $cell.clone().appendTo($row); }); $row.appendTo('tbody'); $('table&gt;tbody&gt;tr&gt;td:nth-child(n+4)').addClass('canDatePicker'); }); $('#adddaterange').click(function () { if ($(".focused").length == 0 || !($(".focused").hasClass("canDatePicker"))) return $(".focused").addClass("hasDatePicker"); $("#datepicker").datepick('show') }); }); </code></pre> <p>Demo: <a href="http://jsfiddle.net/IrvinDominin/WzkBS/" rel="nofollow">http://jsfiddle.net/IrvinDominin/WzkBS/</a></p> <p>Start the demo, press Add row, Add column, focus the new cell and press Add date range, and try to use the demo.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload