title: how to sum column in datatables (i'm using codeigniter)
body: <p>I'm using codeigniter and datatables for my view data. But i'm stuck how to get sum column. I have 2 fields named <strong>barang_qty</strong>, and <strong>barang_qty_toko</strong>. I need to sum this and display on datatables.<br />
  <br />
  This is my Controller :</p>
  
  <pre><code>    function ajax_tableBarang(){
      if(!$this-&gt;input-&gt;is_ajax_request()) {
          exit('No direct script access allowed');
      }else{
          $this-&gt;load-&gt;library('datatables_ssp');
          $table = 'barang';
          $primaryKey = 'barang_id';
  
          $columns = array(
              array( 'db' =&gt; 'barang_id', 'dt' =&gt; 'DT_RowID' ),               
              array( 'db' =&gt; 'barang_kode', 'dt' =&gt; 'barang_kode' ),
              array( 'db' =&gt; 'barang_type', 'dt' =&gt; 'barang_type' ),
              array( 'db' =&gt; 'barang_size', 'dt' =&gt; 'barang_size' ),
              array( 'db' =&gt; 'barang_qty', 'dt' =&gt; 'barang_qty'), //I want this field result from summation of barang_qty and barang_qty_toko
              array( 'db' =&gt; 'barang_harga', 'dt' =&gt; 'barang_harga' ),
              array( 'db' =&gt; 'barang_klasifikasi', 'dt' =&gt; 'barang_klasifikasi'),
  
          );
  
          $sql_details = array(
              'user'  =&gt; 'user',
              'pass'  =&gt; 'passwd',
              'db'    =&gt; 'pjtomato',
              'host'  =&gt; 'localhost'
          );
  
          $where = "";
  
          echo json_encode(Datatables_ssp::simple($_GET, $sql_details, $table, $primaryKey, $columns, $where));
      }
  }
  </code></pre>
  
  <p>And this is my view :</p>
  
  <pre><code>&lt;div role="tabpanel" class="tab-pane fade in active" id="tab-all"&gt;
  &lt;table id="tableAllItem" class="table table-bordered table-striped table-hover" cellspacing="0" width="100%"&gt;
      &lt;thead&gt;
          &lt;tr class="info"&gt;
              &lt;th&gt;#&lt;/th&gt;
              &lt;th&gt;Kode&lt;/th&gt;
              &lt;th&gt;Jenis&lt;/th&gt;
              &lt;th&gt;Ukuran&lt;/th&gt;
              &lt;th&gt;Quantity&lt;/th&gt; // Total of quantity (summation of barang_qty + barang_qty_toko) will display here
              &lt;th&gt;Harga&lt;/th&gt;
              &lt;th&gt;Klasifikasi&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>And this is the javascript for datatables:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $.fn.dataTableExt.oApi.fnPagingInfo = function (oSettings){
      return{
          "iStart": oSettings._iDisplayStart,
          "iEnd": oSettings.fnDisplayEnd(),
          "iLength": oSettings._iDisplayLength,
          "iTotal": oSettings.fnRecordsTotal(),
          "iFilteredTotal": oSettings.fnRecordsDisplay(),
          "iPage": Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
          "iTotalPages": Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
      };
  };
  
  var t = $('#tableAllItem').DataTable({
      "processing": true,
      "serverSide": true,
      "ajax": "&lt;?php echo site_url('cAdminPage/ajax_tableBarang'); ?&gt;",
      "columns": [
      { "data": "barang_kode" },
      { "data": "barang_kode" },
      { "data": "barang_type" },     
      { "data": "barang_size" },
      { "data": "barang_qty"},
      { "data": "barang_harga" },
      { "data": "barang_klasifikasi" },
      ],
  
      "order": [[1, 'asc']],
      "rowCallback": function (row, data, iDisplayIndex){
          var info = this.fnPagingInfo();
          var page = info.iPage;
          var length = info.iLength;
          var index = page * length + (iDisplayIndex + 1);
          $('td:eq(0)', row).html(index);
      }
  });
  </code></pre>
  
  <p></p>
  
  <p>Please advice,
  Thanks</p>