jquery - skipping columns in table javascript -


good day,

i trying skip columns on table not stored variable cant make work.

i want add "skip" class on every "th" element want skip, column shouldn't included on loop.

but stuck on iterating array condition false on next loop causing stored in variable on next loop.

heres js

var = []; var value = [];  $('.report-table tr').each(function(){        $('th', this).each(function(index){             if($(this).hasclass('skip'))             {             console.log(index);             i.push(index);             }             else             {                value.push($(this).text());             }           });    $('td', this).each(function(index){             if(i.length!=0){ //this stuck right                 for(var t = i.length-1; t>=0;t--){                     if(i[t]==index)                     {                         console.log("skip :"+index);                     }                     else{                          value.push($(this).text());                     }                 }             }             else{                 value.push($(this).text());             }          });   }); 

and html

  <table class="report-table table" id="dynamic-report">                <thead>                   <th width="50%">period ending</th>                   <th width="5%" class="rowvalue">jan 31, 2010</th>                   <th width="5%" class="rowvalue skip">feb 31, 2011</th>                   <th width="5%" class="rowvalue">mar 31, 2012</th>                   <th width="5%" class="rowvalue">apr 31, 2010</th>                   <th width="5%" class="rowvalue skip">may 31, 2011</th>                   <th width="5%" class="rowvalue">jun 31, 2012</th>                   <th width="5%" class="rowvalue">jul 31, 2010</th>                   <th width="5%" class="rowvalue">aug 31, 2011</th>                   <th width="5%" class="rowvalue">sep 31, 2012</th>               </thead>               <tbody>              <tr class="indent-0 highlight bold">                  <td>asset</td>                  <td class="emptyrow"></td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>              </tr>              <tr class="indent-1 bold ">                  <td >current assets</td>                  <td class="emptyrow"></td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>               </tr>              <tr  class="indent-2">                 <td>bank accounts</td>                 <td class="emptyrow"></td>                 <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                  <td class="rowvalue">9,999,999.00</td>                </tr>     </tbody> </table> 

you're making more complicated needs be. use jquery index function use index of current td , match index of th , see if th has skip class. click button below see in action. (the undefineds because lazy check empty values!)

just like:

$(function() {  	var results = '';  	$('.report-table tr').each(function (row) {  	  		$('td', this).each(function (index) {            var th;  		  $th = $('.report-table tr th:nth-of-type(' + index + ')');            if ($th.hasclass('skip')) {              results += 'skipping: ' + row + ' / ' + $th.html() + "\n";            } else {              results += 'not skipping: ' + row + ' / ' + $th.html() + "\n";            }  	  		});  	  	});  	alert (results);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table class="report-table table" id="dynamic-report">                  <thead>                    <th width="50%">period ending</th>                    <th width="5%" class="rowvalue">jan 31, 2010</th>                    <th width="5%" class="rowvalue skip">feb 31, 2011</th>                    <th width="5%" class="rowvalue">mar 31, 2012</th>                    <th width="5%" class="rowvalue">apr 31, 2010</th>                    <th width="5%" class="rowvalue skip">may 31, 2011</th>                    <th width="5%" class="rowvalue">jun 31, 2012</th>                    <th width="5%" class="rowvalue">jul 31, 2010</th>                    <th width="5%" class="rowvalue">aug 31, 2011</th>                    <th width="5%" class="rowvalue">sep 31, 2012</th>                </thead>                <tbody>               <tr class="indent-0 highlight bold">                   <td>asset</td>                   <td class="emptyrow"></td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>               </tr>               <tr class="indent-1 bold ">                   <td >current assets</td>                   <td class="emptyrow"></td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                 </tr>               <tr  class="indent-2">                  <td>bank accounts</td>                  <td class="emptyrow"></td>                  <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   <td class="rowvalue">9,999,999.00</td>                   </tr>      </tbody>  </table>


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -