<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
    
    
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th class='text-center', rowspan="2">Location</th>
            <th class='text-center', rowspan="2">Drawing ID</th>
            <th class='text-center', colspan="2">Start Install</th>
            <th class='text-center', rowspan="2">TSSA Forecast</th>
            <th class='text-center', rowspan="2">SAT Forecast</th>
            
          </tr>
          
          <tr>
                        
                        
                        
                        <th class='text-center'>Forecast</th>
                        <th class='text-center'>Actual</th>
                        
            </tr>
        </thead>
        
        <tbody>
          <tr>
            <td>Avenue</td>
            <td>ELV01</td>
            
            <td>15 Jun 2021</td>
            <td>20 Jul 2021</td>
            
            <td>26 Oct 2021</td>
            
            <td></td>
            
            
          </tr>
          <tr>
            <td>Avenue</td>
            <td>ELV02</td>
            
            <td>07 Feb 2022</td>
            <td></td>
           
            <td>16 May 2022</td>
            
            <td></td>
            
          </tr>
           <tr>
            <td>Caledonia</td>
            <td>ELEV-01</td>
            
            <td>20 Jan 2021</td>
            <td>20 Jan 2021</td>
            
            <td>28 Apr 2021</td>
             
            <td></td>
            
          </tr>
            <tr>
            <td>Caledonia</td>
            <td>ELEV-02</td>
              
            <td>07 Dec 2021</td>
            <td>07 Dec 2021</td>
              
            <td>15 Mar 2022</td>
              
            <td></td>
            
          </tr>
          <tr>
            <td>Cedarvale</td>
            <td>ELV01</td>
              
            <td>15 Nov 2021</td>
            <td>16 Nov 2021</td>
              
            <td>22 Feb 2022</td>
              
            <td></td>
            
          </tr>
          <tr>
            <td>Cedarvale</td>
            <td>ELV02</td>
              
            <td>15 Nov 2021</td>
            <td>16 Nov 2021</td>
              
            <td>22 Feb 2022</td>
              
            <td></td>
            
          </tr>
            <tr>
            <td>Cedarvale</td>
            <td>ELV03</td>
              
            <td>16 Feb 2022</td>
            <td></td>
              
            <td>25 may 2022</td>
              
            <td></td>
            
          </tr>
            <tr>
            <td>Cedarvale</td>
            <td>ELV04</td>
              
            <td>19 Jul 2021</td>
            <td>21 Jul 2021</td>
              
            <td>27 Oct 2021</td>
              
            <td></td>
            
          </tr>
            <tr>
            <td>Chaplin</td>
            <td>ELV01</td>
              
            <td>25 Oct 2021</td>
            <td>26 Oct 2021</td>
              
            <td>01 Feb 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Chaplin</td>
            <td>ELV02</td>
              
            <td>12 Jan 2022</td>
            <td></td>
              
            <td>20 Apr 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Eglinton</td>
            <td>ELV01</td>
              
            <td>23 Feb 2022</td>
            <td></td>
              
            <td>01 Jun 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Eglinton</td>
            <td>ELV02</td>
              
            <td>20 Feb 2022</td>
            <td></td>
              
            <td>29 May 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Eglinton</td>
            <td>ELV03</td>
              
            <td>14 Jun 2022</td>
            <td></td>
              
            <td>20 Sep 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Eglinton</td>
            <td>ELV04</td>
              
            <td>05 May 2022</td>
            <td></td>
              
            <td>11 Aug 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Eglinton</td>
            <td>ELV05</td>
              
            <td>27 Apr 2022</td>
            <td></td>
              
            <td>03 Aug 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Eglinton</td>
            <td>ELV06</td>
              
            <td>31 Mar 2022</td>
            <td></td>
              
            <td>07 Jul 2022</td>
              
            <td></td>
          </tr>
          <tr>
            <td>Eglinton</td>
            <td>ELV07</td>
              
            <td>36 Mar 2022</td>
            <td></td>
              
            <td>22 Jun 2022</td>
              
            <td></td>
          </tr>
          
        </tbody>
      </table>
    </div>
  </body>
</html>
 
body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: #fff;
}
 
$(document).ready( function () {
  
  var table = $('#example').DataTable({
    
   
     
    dom: 'Bfrtip',
    orderFixed: [[0, 'asc'], [1, 'asc']],
    drawCallback: function(){
        var api = this.api();
       
        var result = {};
        // Loop all cells in Location column
        api.cells(null, 0).every( function (rowIdx){
            var data = this.data();
            if( ! result.hasOwnProperty( data)){
                result[data] = 0;
            }
        
        
        // Get the TSSA Forecast date from the same row
          var Tssa = api.cell( rowIdx, 4).data();
          
          // Keep track of latest Tssa date
          if ( result[data] < moment(Tssa )) {
            result[data] = moment(Tssa);
          }
          
          
        
    });
    console.log(result);
      
    var currentLocation = ''; // Keep track of Location changes
      
    // Loop through all the rows and store the lates date, per Locaiton, +14 days
    api.cells(null, 0).every( function (rowIdx){
        var data = this.data();
      
      // If Location changes then update tracker and reset increment counter
      if (data !== currentLocation ) {
        currentLocation = data;
        incrementCounter = 14;
      }
      
        var ans = moment( result[data] ).add(incrementCounter, 'days');
        incrementCounter++; 
      
        api.cell( rowIdx, 5).data(moment(ans).format('DD MMM YYYY'));
    });
  },
    
  });
} );
  
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers