hide table rows based on date

MTplus

I have a HTML table filled with events. Each event has a date. The table rows look like this:

<div class="table-responsive">
  <table>
    <thead>
      <tr>
        <th>Date</th>
        <th>Event</th>
      </tr>
    </thead>
    <tbody>  
      <tr data-date="2017-03-27">
        <td>2017-03-27</td>
        <td>My event detail</td>
      </tr>
      <tr data-date="2017-03-28">
        <td>2017-03-28</td>
        <td>My event detail 2</td>
      </tr>                  
    </tbody>
  </table>
</div>

Based on the current date I want to hide all rows/events that are older than current date. I'm thinking this could be achieved using a jQuery function that runs when the page loads. Can anyone show me how I could do this?

Azeez Kallayi

This may help you

$(document).ready(function(e) {
    $('.event_display_table tbody tr').each(function(index, element) {
        event_day = $(this).attr('data-date');
		event_day = new Date(event_day);
		//today = new Date('2017-03-14');
		today = new Date();
		if(event_day.getTime() < today.getTime())
		{ 
		   $(this).css('display','none');
		}
		
		console.log($(this).attr('data-date'));
		
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="table-responsive">
          <table class="event_display_table"  border="1" >
            <thead>
              <tr>
                <th>Date</th>
                <th>Event</th>
              </tr>
            </thead>
            <tbody>
               <tr data-date="2017-03-13">
                <td>2017-03-13</td>
                <td>My event detail 2</td>
              </tr>                  
                <tr data-date="2017-03-15">
                <td>2017-03-15</td>
                <td>My event detail 2</td>
              </tr>                  

              <tr data-date="2017-03-27">
                <td>2017-03-27</td>
                <td>My event detail</td>
              </tr>

              <tr data-date="2017-03-28">
                <td>2017-03-28</td>
                <td>My event detail 2</td>
              </tr>                  

            </tbody>
          </table>
        </div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Show and hide table rows in angularjs

Android: hide / show table rows

How to count rows from a different table based on same date range

Hide rows based on cell value

Counting previous rows in a data table based on date

How to hide table rows based on child class name using jquery?

Hide table rows with jquery

Hide empty html table rows

date in multiple table rows

Hide and show rows in a table

Based on user position, hide rows in table -5 and +5 after name (jquery)

AngularJS: Hide Empty Table based on checked rows in Table One

Hide rows based on multiple cells

Show/Hide Table Rows based on Checkbox

select rows from main table based on highest date in child table between a date range

Show/Hide Table Rows with Javascript

HTML Hide Table rows

jQuery: Hide/Show table rows based on clicked button

SQL Hide/Show rows based on row count from another table

Hide dropdown options based on date

Hide table rows based on date AND click a button to show them again

Hide Rows based on Date in Column

Insert rows in table based on date logic - sql/hive

Shiny DTedit, show or hide insert/new button based on rows_selected status in second DTedit table

Hide orders (table rows) in WooCommerce admin order list based on order status

How to hide table rows that fetch the info from a database based on string given and when a button is pressed

Show or hide table rows based on text value in Blazor

Creating rows in a table based on min and max date in Snowflake SQL

Get rows based on max date and other filters from the table