Page 1 of 1

Color variation for table cell - Date

Posted: 2023-12-07 15:12
by azhar
Dear Appgineers,

The code below accomplishes the desired task by turning the cell red in a table if the date is today and beyond. However, it also turns the cell red when the field is blank. How can this be modified in the code?

Code: Select all

<script>
jQuery(document).ready(function() {
  var tbody = $j('tbody');
  tbody.find('tr').each(function(){
    var dateTD = $j($(this).querySelector('.bookings-balance_payment_due_date'));
    var date = dateTD.text();
    var today = new Date(Date.now()).toLocaleString().split(',')[0]
  
    if (date > today)
    dateTD.addClass('danger');
  });
});
</script>

Re: Color variation for table cell - Date

Posted: 2023-12-07 18:14
by SkayyHH
I have this code which works for me. But I can't help more. Someone wrote it to me too :-)

You can set the time before/after the date.

Code: Select all

				<script>
				const current = Date.parse(new Date());
				const y=new Date().getFullYear(); 
				$j(\'td.employees_de-date_of_birth a:contains(".")\').each(function() {
   					t=$j(this).text().substr(0,5).split(".");
   					comp=new Date(y,t[1]-1,t[0]);
   					diff=parseInt(((current-comp)/1000/60/60/24).abs())
   					if (diff <=15) {
						$j(this).parent().addClass("danger");
   					}
				})
				</script>';