How to hide a table row if date in td is older than today's date?

前端 未结 2 617
情话喂你
情话喂你 2021-01-27 19:56

As a Dr. Frankenstein of coding, I have managed to cobble together a table as exampled [here][1], utilising datatables and UK Date Sorting. The final piece of this puzzle is to

相关标签:
2条回答
  • 2021-01-27 20:23

    Give that particular td some class say "clsdate".Then point the class and find the html and convert that to date. Find the difference and do the necessary

    $('table').find(".clsdate").each(function(index,element){
      var tdDate=new Date($(element).html());
      var currDate=getDate();
      var diff=currDate-tdDate;
       if(diff<0)
       {
         $(element).parent('tr').css('display','none');
       }
    });
    
    0 讨论(0)
  • $(document).ready(function() {
    
        $("#table_id").dataTable({"aoColumnDefs" : [
          {"aTargets" : [2] , "sType" : "uk_date"}]});
    
      $('TD.date').each(function( index ) {  
        var q = new Date();
        var m = q.getMonth();
        var d = q.getDay();
        var y = q.getYear();
    
        var date = new Date(y,m,d);
        if(new Date($(this).text()) < date)    {
    
            $(this).parent().attr("style", "display: none")
        }
          });
    
    });
    

    and add a date class to the column that contains the date.

    0 讨论(0)
提交回复
热议问题