title: JQuery Datatables + Codeigniter (Static cols)
body: <p>I am using Codeigniter with JQuery Datatables to present data from MYSQL database with realtime updates via AJAX/JSON requests. I am not the original developer of this code that's why I am not being able to solve this problem I guess.</p>
  
  <p>What I have is a table with 26 columns, not all of them are yet populated but it seems that all of them are there straight from the database. This is how piece of the code from json_table function looks:</p>
  
  <pre><code>$this-&gt;load-&gt;model('aircraft_model');
  $this-&gt;load-&gt;model('nats_model');
  
  $aColumns = array('FlightSts', 'TblOrder', 'Callsign', 'Destination', 'NAT', 'SELCAL', 'CldFL', 'CldMach', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'FlightID');
  $sTable = 'naecs_aircraft';
  </code></pre>
  
  <p>$stable seems to be mysql table which is correct,
  $acolumns seems to be all fields from the mysql table naecs_aircraft. That's all correct and it even works but in Second last column, just before FlightID I want to populate a button. So basically In the second last collumn I want to have a button.</p>
  
  <p>How to do it?</p>
  
  <p>Regards,
  Maciej.</p>
  
  <p>@edit1</p>
  
  <p>This is whole function within the controller ajax.php:</p>
  
  <pre><code>public function json_table(){
      $this-&gt;access-&gt;requires(ACCESS_USER);
      $this-&gt;load-&gt;model('aircraft_model');
      $this-&gt;load-&gt;model('nats_model');
  
      $aColumns = array('FlightSts', 'TblOrder', 'Callsign', 'Destination', 'NAT', 'SELCAL', 'CldFL', 'CldMach', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'FlightID');
      $sTable = 'naecs_aircraft';
  
      $iDisplayStart = $this-&gt;input-&gt;get_post('iDisplayStart', true);
      $iDisplayLength = $this-&gt;input-&gt;get_post('iDisplayLength', true);
      $iSortCol_0 = $this-&gt;input-&gt;get_post('iSortCol_0', true);
      $iSortingCols = $this-&gt;input-&gt;get_post('iSortingCols', true);
      $sSearch = $this-&gt;input-&gt;get_post('sSearch', true);
      $sEcho = $this-&gt;input-&gt;get_post('sEcho', true);
  
      if(isset($iSortCol_0))
      {
          for($i=0; $i&lt;intval($iSortingCols); $i++)
          {
              $iSortCol = $this-&gt;input-&gt;get_post('iSortCol_'.$i, true);
              $bSortable = $this-&gt;input-&gt;get_post('bSortable_'.intval($iSortCol), true);
              $sSortDir = $this-&gt;input-&gt;get_post('sSortDir_'.$i, true);
  
              if($bSortable == 'true')
              {
                  if ($aColumns[$iSortCol] != ' '){
                      $this-&gt;aircraft_model-&gt;json_table_sort($aColumns, $iSortCol, $sSortDir);
                  }
              }
          }
      }
  
      if(isset($sSearch) &amp;&amp; !empty($sSearch))
      {
          for($i=0; $i&lt;count($aColumns); $i++)
          {
              if ($aColumns[$i] != ' '){
                  $bSearchable = $this-&gt;input-&gt;get_post('bSearchable_'.$i, true);
                  if(isset($bSearchable) &amp;&amp; $bSearchable == 'true')
                  {
                      $this-&gt;aircraft_model-&gt;json_table_filter($aColumns, $i, $sSearch);
                  }
              }
          }
      }
  
      $rResult = $this-&gt;aircraft_model-&gt;json_table_select($aColumns, $sTable);
      $iFilteredTotal = $this-&gt;aircraft_model-&gt;json_table_found($aColumns);
      $iTotal = $this-&gt;aircraft_model-&gt;count_all($sTable);
  
      $output = array(
          'sEcho' =&gt; intval($sEcho),
          'iTotalRecords' =&gt; $iTotal,
          'iTotalDisplayRecords' =&gt; $iFilteredTotal,
          'aaData' =&gt; array()
      );
  
      $headers = array('3active' =&gt; FALSE, '2cleared' =&gt; FALSE, '4closed' =&gt; FALSE, '1entered' =&gt; FALSE, '5disconnected' =&gt; FALSE);
  
      foreach($rResult-&gt;result_array() as $aRow)
      {
          $row = array();
  
          foreach($aColumns as $col)
          {
              @$row[] = $aRow[$col];
          }
  
          $databit = $row;
          $databit['DT_RowId'] = $aRow['FlightID'];
          $databit['DT_RowName'] = $aRow['Callsign'];
          $output['aaData'][] = $databit;
          $headers[$aRow['FlightSts']] = TRUE;
      }
  
      foreach ($headers as $key =&gt; $value){
          if ($value == FALSE){
              $output['aaData'][] = array($key, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
          }
      }
  
      $output['aaData'][] = array('No More Aircraft', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
  
      echo json_encode($output);
  }
  </code></pre>
  
  <p>tableinit.js:</p>
  
  <pre><code>function initTable(){
      oTable = $('#main-table').dataTable({
          "bProcessing": true,
          "bServerSide": true,
          "bSort": true,
          "sServerMethod": "GET",
          "sAjaxSource": "ajax/json_table",
          "oLanguage": { "sProcessing": "&lt;i class='icon-refresh icon-spin'&gt;&lt;/i&gt;" },
          "sDom": "&lt;'pull-right'r&gt;&lt;'row'&lt;'span8'l&gt;&gt;tS",
          "sScrollY": "400px",
          "bPaginate": false,
          "bScrollCollapse": true,
          "aoColumnDefs": [ 
          { "bVisible": false,  "aTargets": [ 1, 25 ] },
          ],
          "aaSorting": [[ 1, "asc" ]],
          "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
              $('td:eq(0)', nRow).attr("name", "callsign");
              $('td:eq(1)', nRow).attr("name", "destination");
              $('td:eq(2)', nRow).attr("name", "nat");
              $('td:eq(3)', nRow).attr("name", "selcal");
              $('td:eq(4)', nRow).attr("name", "lvl");
              $('td:eq(5)', nRow).attr("name", "mach");
          },
      }).rowGrouping({ iGroupingColumnIndex: 0, sGroupingClass: 'nodrop', bSetGroupingClassOnTR: true });
  }
  </code></pre>