user3023588 user3023588 - 7 months ago 10
HTML Question

How to remove date value from td if is the same date value?

I have a table where my date value repeats for each table row. I tried to fix this problem with SQL inside of my query but that can not be done there so I'm looking for other solution with Javascript or JQuery to fix this problem. So I would like to remove date values if they repeat but if date value changed in my td I would keep it. Here is how table looks:

Date Time
10/19/2016 8:00 AM - 8:30 AM
10/19/2016 8:30 AM - 9:00 AM
10/19/2016 9:00 AM - 9:30 AM
10/19/2016 9:30 AM - 10:00 AM
10/19/2016 10:00 AM - 10:30 AM
10/19/2016 10:30 AM - 11:00 AM
10/19/2016 11:00 AM - 11:30 AM
10/19/2016 11:30 AM - 12:00 PM
10/19/2016 12:00 PM - 12:30 PM
10/19/2016 12:30 PM - 1:00 PM
10/19/2016 1:00 PM - 1:30 PM
10/19/2016 1:30 PM - 2:00 PM
10/20/2016 9:00 AM - 9:20 AM
10/20/2016 9:20 AM - 9:40 AM
10/20/2016 9:40 AM - 10:00 AM
10/20/2016 10:00 AM - 10:20 AM
10/20/2016 10:20 AM - 10:40 AM
10/20/2016 10:40 AM - 11:00 AM
10/20/2016 11:00 AM - 11:20 AM
10/20/2016 11:20 AM - 11:40 AM
10/20/2016 11:40 AM - 12:00 PM
10/20/2016 12:00 PM - 12:20 PM
10/20/2016 12:20 PM - 12:40 PM
10/20/2016 12:40 PM - 1:00 PM
10/20/2016 1:00 PM - 1:20 PM
10/20/2016 1:20 PM - 1:40 PM
10/20/2016 1:40 PM - 2:00 PM
10/20/2016 2:00 PM - 2:20 PM
10/20/2016 2:20 PM - 2:40 PM


As you can see above this is very confusion with all dates listed for each row, I would like to keep just first date value for each date. Something like this:

Date Time
10/19/2016 8:00 AM - 8:30 AM
8:30 AM - 9:00 AM
9:00 AM - 9:30 AM
9:30 AM - 10:00 AM
10:00 AM - 10:30 AM
10:30 AM - 11:00 AM
11:00 AM - 11:30 AM
11:30 AM - 12:00 PM
12:00 PM - 12:30 PM
12:30 PM - 1:00 PM
1:00 PM - 1:30 PM
1:30 PM - 2:00 PM
10/20/2016 9:00 AM - 9:20 AM
9:20 AM - 9:40 AM
9:40 AM - 10:00 AM
10:00 AM - 10:20 AM
10:20 AM - 10:40 AM
10:40 AM - 11:00 AM
11:00 AM - 11:20 AM
11:20 AM - 11:40 AM
11:40 AM - 12:00 PM
12:00 PM - 12:20 PM
12:20 PM - 12:40 PM
12:40 PM - 1:00 PM
1:00 PM - 1:20 PM
1:20 PM - 1:40 PM
1:40 PM - 2:00 PM
2:00 PM - 2:20 PM
2:20 PM - 2:40 PM


Here is my code that I currently use to output values to the screen:

<table>
<thead>
<tr>
<th>Date</th>
<th>Time Slots</th>
</tr>
</thead>
<tbody>
~[tlist_sql;
Select to_char(PTC_DATE,'mm/dd/yyyy'),SLOT_LABEL
From EVENT_SLOTS
Where e.EVENT_ID = '145'
Order by PTC_DATE, DISPLAY_ORDER;]
<tr>
<td>~(PTC_DATE)</td>
<td>~(SLOT_LABEL)</td>
</tr>
[/tlist_sql]
</tbody>
</table>


What would be if it's even possible to remove duplicate date values in my Date td tag? If anyone can help please let me know. Thanks.

RAS RAS
Answer

Okay, if you really want to manipulate this in jquery/javascript add class to each date <td> tag and run this code:

    var placeholder = '';
$(".date").each(function() {
  if (placeholder != '') {
    if (placeholder == $(this).text()) {
      $(this).text("");
    } else {
      placeholder = $(this).text();
    }
  } else {
    placeholder = $(this).text();
  }
});

https://jsfiddle.net/j4v387nu/