2017-01-12 3 views
0

MySQLデータベースのデータをデータテーブルに表示するCodeIgniterアプリケーションを開発しています。CodeIgniter 2.2のDatatableでサーバー側のMySQLデータが表示されない

コントローラは必要なデータを返しますが、何も表示されません。関連するコードスニペットは、次のとおりです。

<!--table--><div class="widget-body no-padding"> 

          <table id="datatable_tabletools" class="table table-striped table-bordered table-hover" width="100%"> 
           <thead> 
            <tr> 
             <th data-class="expand">StaffId</th> 
             <th data-hide="phone">Narration</th> 
             <th data-hide="phone">Account Number</th> 
             <th data-hide="phone">Bank</th> 
             <th data-hide="phone,tablet">Amount</th> 
                      </tr> 
           </thead> 

          </table> 

         </div> 
         <!-- end widget content --> 

JavaScriptがデータテーブルを初期化する

<script type="text/javascript"> 

// DO NOT REMOVE : GLOBAL FUNCTIONS! 

$(document).ready(function() { 

    /* TABLETOOLS */ 
    $('#datatable_tabletools').dataTable({ 
     "bServerSide":true, 
       "bProcessing": false, 
       "sServerMethod": "POST", 
       // Load data for the table's content from an Ajax source 
     "ajax":{'url':"<?php echo APP_URL.'/index.php/payments/seed';?>", 
      'type':'POST',}, 
       "aoColumns": [ 

         { "data": "reference" }, 
         { "data": "narration" }, 
         { "data": "accountnumber" }, 
         { "data": "amount" }, 
         { "data": "bank" } 

       ], 

      "sSwfPath": "<?php echo base_url("js/plugin/datatables/swf/copy_csv_xls_pdf.swf"); ?>" 
     }, 
     "autoWidth" : true, 
     "preDrawCallback" : function() { 
      // Initialize the responsive datatables helper once. 
      if (!responsiveHelper_datatable_tabletools) { 
       responsiveHelper_datatable_tabletools = new ResponsiveDatatablesHelper($('#datatable_tabletools'), breakpointDefinition); 
      } 
     }, 
     "rowCallback" : function(nRow) { 
      responsiveHelper_datatable_tabletools.createExpandIcon(nRow); 
     }, 
     "drawCallback" : function(oSettings) { 
      responsiveHelper_datatable_tabletools.respond(); 
     } 
    }); 

    /* END TABLETOOLS */ 

}) 

</script> 

私のコントローラ下のショーである:

public function seed() 
    { 
     $aColumns = array('reference','narration','accountnumber','amount','bank'); 

     // DB table to use 
     $sTable = 'g'; 
     // 

     $iDisplayStart = $this->input->get_post('iDisplayStart', true); 
     $iDisplayLength = $this->input->get_post('iDisplayLength', true); 
     $iSortCol_0 = $this->input->get_post('iSortCol_0', true); 
     $iSortingCols = $this->input->get_post('iSortingCols', true); 
     $sSearch = $this->input->get_post('sSearch', true); 
     $sEcho = $this->input->get_post('sEcho', true); 


     // Paging 
     if(isset($iDisplayStart) && $iDisplayLength != '-1') 
     { 
      $this->db->limit($this->db->escape_str($iDisplayLength), $this->db->escape_str($iDisplayStart)); 
     } 

     // Ordering 
     if(isset($iSortCol_0)) 
     { 
      for($i=0; $i<intval($iSortingCols); $i++) 
      { 
       $iSortCol = $this->input->get_post('iSortCol_'.$i, true); 
       $bSortable = $this->input->get_post('bSortable_'.intval($iSortCol), true); 
       $sSortDir = $this->input->get_post('sSortDir_'.$i, true); 

       if($bSortable == 'true') 
       { 
        $this->db->order_by($aColumns[intval($this->db->escape_str($iSortCol))], $this->db->escape_str($sSortDir)); 
       } 
      } 
     } 





     if(isset($sSearch) && !empty($sSearch)) 
     { 
      for($i=0; $i<count($aColumns); $i++) 
      { 
       $bSearchable = $this->input->get_post('bSearchable_'.$i, true); 

       // Individual column filtering 
       if(isset($bSearchable) && $bSearchable == 'true') 
       { 
        $this->db->or_like($aColumns[$i], $this->db->escape_like_str($sSearch)); 
       } 
      } 
     } 

     // Select Data 
     $rResult=$this->db->query('select SQL_CALC_FOUND_ROWS reference,narration,accountnumber,amount,bank_name bank 
     from g join bank_data on bank_data.bank_code =g.destinationcode') 
     ; 
      $iFilteredTotal =$rResult->num_rows(); 

     // Total data set length 
     $iTotal = $rResult->num_rows(); 
     // $iTotal = $this->db->count_all($sTable); 

     // Output 
     $output = array(
      'sEcho' => intval($sEcho), 
      'iTotalRecords' => $iTotal, 
      'iTotalDisplayRecords' => $iFilteredTotal, 
      'aaData'=>array() 
     ); 


     foreach($rResult->result_array() as $aRow) 
     { 
      $row = array(); 

      foreach($aColumns as $col) 
      { 
       $row[$col]=$aRow[$col]; 
      } 

      $output['aaData'][]=$row; 
     } 

     echo json_encode($output); 



    } 

返されるJSONのサンプル私はコントローラである呼び出すとき:

{"sEcho":0,"iTotalRecords":22631,"iTotalDisplayRecords":22631,"aaData":[{"reference":"0015432969","narration":"BVFFEEW","accountnumber":"gfhfhf","amount":"100.00","bank":"NANJK"} 
+0

「再生できません」と閉じることができます。 – halfer

答えて

0

非常に長い遅延の後にコードが最終的に機能し、データが返されていないと仮定することができました。遅延は結果セットのサイズに起因していました。私が使用したカスタムクエリは、新しい問題を提起することによって、次に解決しなければならないページングを強制しませんでした。ありがとうございました

関連する問題