Color variation for table cell - Date

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
azhar
Posts: 21
Joined: 2023-11-19 17:19

Color variation for table cell - Date

Post by azhar » 2023-12-07 15:12

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>

SkayyHH
Veteran Member
Posts: 427
Joined: 2015-04-27 21:18

Re: Color variation for table cell - Date

Post by SkayyHH » 2023-12-07 18:14

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>';

Post Reply