title: jQuery: SUM of columns and merge them to one cell (Replace them with SUM result)
body: <p>I want to change this table:</p>
  <p><img src="https://i.stack.imgur.com/P5XDn.png" alt="enter image description here" /></p>
  <h3>Is that possible With jQuery?</h3>
  <p>If yes, please just send me similar example or any workaround.</p>
  <p>EDIT:
  I knew how to read all td's</p>
  <pre><code>$('#tableid tbody tr').each(function() {
  
      $.each(this.cells, function(){
          var celltext = $(this).text();
      });
  
  });
  </code></pre>
  <p>Also, this how each similar value can be grouped to one cell:</p>
  <pre><code>var $rows = $('#tableid tbody tr');
  var items = [],
      itemtext = [],
      currGroupStartIdx = 0;
  $rows.each(function(i) {
      var $this = $(this);
      var itemCell = $(this).find('td:eq(0)');
      var item = itemCell.text();
      itemCell.remove();
      if ($.inArray(item, itemtext) === -1) {
          itemtext.push(item);
          items.push([i, item]);
          groupRowSpan = 1;
          currGroupStartIdx = i;
          $this.data('rowspan', 1)
      } else {
          var rowspan = $rows.eq(currGroupStartIdx).data('rowspan') + 1;
          $rows.eq(currGroupStartIdx).data('rowspan', rowspan);
      }
  
  });
  
  $.each(items, function(i) {
      var $row = $rows.eq(this[0]);
      var rowspan = $row.data('rowspan');
      $row.prepend('&lt;td rowspan=&quot;' + rowspan + '&quot; style=&quot;white-space:nowrap;&quot;&gt;' + this[1] + '&lt;/td&gt;');
  });
  </code></pre>
  <p>This is PHP Solution so far:</p>
  <pre><code>foreach($tabledata as $key =&gt; $val){
   $rowspan = (count($val) &gt; 1 ? ' rowspan=&quot;'.count($val).'&quot; ' : '');
     $spancount = 0;
     foreach($val as $vkey =&gt; $vval){
       $spancount++;
        echo '
        &lt;tr&gt;
        ';
         if($spancount == 1){
          echo '
          &lt;td'.$rowspan.'&gt;'.$key.'&lt;/td&gt;
          ';
         }
        echo '
        &lt;td&gt;'.$vval[0].'&lt;/td&gt;
        ';
        echo '
        &lt;td&gt;'.$vval[1].'&lt;/td&gt;
        ';
       if($spancount == 1){
        echo '
        &lt;td'.$rowspan.'&gt;'.$sums[$key].'&lt;/td&gt;
        ';
       }
        echo '&lt;/tr&gt;
        ';
     }
  }
  </code></pre>