Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with table output and calendar picker bug

Status
Not open for further replies.

jason.lex

Vendor
Jan 3, 2019
10
HK
I have been trying to display a table when a user select a data from the datepicker and display a table with the number of columns equal to the number of days to the select month.
However, I have 2 issues and I am not sure I to fix them...

- The datapicker although when selected a specific month, it actually display the previous month instead (ie. selected April, it shows March).

- Portions of the table is shown, is there a way to hide them before a month is selected?

Here is the link to the script I am writing.

Here is the code for generating the table...

PHP:
<div class="pull-right form-inline" style="margin-bottom:10px;">
    <div class="form-group">
        <div class='input-group date' id='m_picker'>
          <div class="form-control"><?=!empty($selected_month)?date('Y / m',$selected_time):'Select Month'?></div>
          <input type='hidden' value="<?=!empty($selected_month)?date('Y-m',$selected_time):''?>" />
          <span class="input-group-addon">
            <span class="glyphicon glyphicon-calendar"></span>
          </span>
        </div>
    </div>
  </div>
  
 <table id="table2" width="100%" style="margin-top: 10px;">
  <tbody>
    <tr>
      <td class="text-right">Date</td>
        <? for ($d = 1; $d <= $days; $d++)    
      	 echo "<td colspan=\"2\" class=\"text-center\">{$d}</td>"; ?>
    </tr>
    <tr>
      <td class="text-center">Group</td>
       <? for ($d = 1; $d <= $days; $d++) {   
       echo "<td class=\"text-center\">Hours</td>
      <td class=\"text-center\">Number</td>"; }?>
    </tr>
    <? for ($i = 1; $i <= 10; $i++) {
		echo "<tr>
      <td class=\"text-center\">name</td>";
	      for ($d = 1; $d <= $days; $d++) {
    	echo "<td class=\"text-right text-blue\">num1</td>
      <td class=\"text-right text-red\">num2</td>"; }
	    echo "</tr>";} ?>
    <tr>
      <td class="text-center"></td>
      <? for ($d = 1; $d <= $days; $d++) { 
		echo "<td class=\"text-right\">num1</td>
      <td class=\"text-right\">num2</td>";} ?>
    </tr>
  </tbody>
</table>

<script type="text/javascript">
    var test;
		$(function () {
      $('#m_picker').datetimepicker({
        format: 'YYYY / MM',
        viewMode: 'months'
      });
      $('#m_picker').on('dp.hide', function(e){
        $('#m_picker>div.form-control').text($('#m_picker>input').val());
        var select_date = e.date._d;
        var month=Math.floor(new Date(select_date).getTime()/1000);
        location.href='_tablework.php?m='+ month;
      });
    });
	</script>

 
It looks like the first point has already been addressed.

Before a month is selected, there is no "m" GET value in the URL. You just need to create a conditional situation where you produce the table (empty or not) only when the "m" value is set or not empty.
 
Hi spamjim,

Thank you for your reply. Thanks for the tips for the second one.

The first one seems to be happening when you pick another month the second time and so on. It didn't seems to happened when you initially pick a month however... Which is weird....
 
The date displays as expected (2019 / xx) after repeated calendar selections. The number of days per month also appears to be correct for each month selection (28/30/31). Is it possible you have some browser or proxy caching interfering with the output?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top