2016-07-27 118 views
3

說實話,我對代碼的運行方式一無所知,我一直在做這件事,「讀完這些之後,沒有任何結果。我在編程方面還是個新手。主要問題是使用Ignited-Datatable 2.0 beta和Datatables 1.10.12我使用MVC模式,我已經看到了CV模式。Ignited-Datatables,應該怎麼做?

這是MySQL查詢我試着點燃的風格,使:

$sql = 
     "SELECT GROUP_CONCAT(a.servicio) AS Num_Servicio_Campus, 
     GROUP_CONCAT(DISTINCT (b.account)) AS Total_Cuentas, 
     GROUP_CONCAT(DISTINCT(YEAR(a.periodo_fin))) AS YearFin, 
     CONCAT('', FORMAT(SUM(a.consumo), 0)) AS SumatoriaConsumoEnergia, 
     CONCAT('$', FORMAT(SUM(a.costo), 2)) AS SumatoriaCostoEnergia, c.campus AS Campus 
     FROM `sdspanel1`.`pdc_consumo_energia` a 
     INNER JOIN `sdspanel1`.`ctrl_servicios` b ON(a.servicio = b.id) 
     INNER JOIN `sdspanel1`.`pdc_servicios_energia` c ON(c.cuenta = b.account) 
     WHERE c.campus IS NOT NULL AND c.campus <> '' 
     AND a.periodo_fin IS NOT NULL AND a.periodo_fin <> '' 
     AND (YEAR(a.periodo_fin) <'1-12-31' OR YEAR(a.periodo_fin)> '2010-12-31') 
     AND (YEAR(a.periodo_fin) <'2100-12-31' OR YEAR(a.periodo_fin)> '2100-12-31')"; 

     $sql .= " GROUP BY YEAR(a.periodo_fin), c.campus 
      ORDER BY YEAR(a.periodo_fin) ASC, a.servicio ASC"; 

     $query = $this->db->query($sql); 

     if($query->num_rows() > 0) 
     { 
      return $query->result_array(); 

     } 
     else 
     { 
      return FALSE; 
     } 

Query Results

而且它的工作原理,但需要在數據表的方式進行排序。並嘗試這樣的Stack Example,但沒有結果。

所以...這是我點燃的數據表 「嘗試」 MODEL

function lista_campus() 
{ 
    $this->load->library('datatables'); 
    $this->datatables->FROM('pdc_consumo_energia'); 
    $this->datatables->SELECT("pdc_servicios_energia.campus AS Campus, 
    GROUP_CONCAT(pdc_consumo_energia.servicio) AS Num_Servicio_Campus, 
    GROUP_CONCAT(DISTINCT(YEAR(pdc_consumo_energia.periodo_fin))) AS YearFin, 
    CONCAT('', FORMAT(SUM(pdc_consumo_energia.consumo), 0)) AS SumatoriaConsumoEnergia, 
    CONCAT('$', FORMAT(SUM(pdc_consumo_energia.costo), 2)) AS SumatoriaCostoEnergia, 
    GROUP_CONCAT(DISTINCT(ctrl_servicios.account)) AS Total_Cuentas", FALSE); 
    $this->datatables->JOIN('ctrl_servicios', 'pdc_consumo_energia.servicio = ctrl_servicios.id', 'INNER'); 
    $this->datatables->JOIN('pdc_servicios_energia', 'pdc_servicios_energia.cuenta = ctrl_servicios.account', 'INNER'); 
    $this->datatables->WHERE('pdc_servicios_energia.campus IS NOT NULL AND pdc_consumo_energia.periodo_fin IS NOT NULL'); 
    $this->datatables->GROUP_BY('pdc_consumo_energia.periodo_fin', 'pdc_servicios_energia.campus'); 
    return $this->datatables->generate('json', ''); 



} 

控制器:

function campus_buscar3() 
{ 
    // /* Configuración de la paginación */ 

    $this->modelo_consumo_energia->lista_campus(); 
    $data['title'] = '<i class="icon-fire"></i> TEST'; 
    $data['subtitle'] = 'Test Vista Campus'; 
    $data['body'] = 'busqueda_electricidad_campus_c'; 
    $this->load->view('main', $data); 


} 

如果我嘗試做 「示例」 的方式,它可以不顯示東西...

「最後... View/JScript:

<script type="text/javascript" charset="utf-8"> 
      $(document).ready(function() { 
      //$(function() { 
      $('#Campusini').dataTable({ 


       //"order": [[ 1, "asc" ]], 

       /*"aoColumnDefs": [ 
        { 'bSortable': false, 'aTargets': [ 3 ]}, 
        { 'bSearchable': true } 
       ],*/ 
       "Processing": true, 
       "ServerSide": true, 
       "sAjaxSource": '<?php echo site_url(); ?>consumo_electricidad/campus_buscar3', 
       "bJQueryUI": true, 
       "sPaginationType": "full_numbers", 
       "iDisplayStart ":20, 
       "oLanguage": { 
       "sProcessing": "" 
       }, 

       "aoColumns": [ 
         { "bSearchable": true, "bSortable": true, "mData": "YearFin" }, 
         { "bSearchable": true, "bSortable": true, "mData": "SumatoriaConsumoEnergia" }, 
         { "bSearchable": true, "bSortable": true, "mData": "SumatoriaCostoEnergia" }, 
         { "bSearchable": true, "bSortable": true, "mData": "Campus" } 
       ], 

       'fnServerData': function(sSource, aoData, fnCallback) 

       { 
        $.ajax 
        ({ 
         'dataType': 'json', 
         'type' : 'POST', 
         'url'  : sSource, 
         'data' : aoData, 
         'success' : fnCallback 
        }); 
       } 
      }); 
     }); 
</script> 




    <table id= "Campusini" class = "table table-bordered datatable table-striped"> 
     <thead> 
      <tr> 

      <th> Año </th> 
      <th> Consumo Total </th> 
      <th> Costo Total </th> 
      <th> Campus </th> 
      </tr> 
     </thead> 
     </table> 

With no results at all...。 所以任何幫助這個混亂很受歡迎。提前致謝。

回答

0

很難回答所有......但我可能看到的錯誤:

在調用該函數

$這個 - > modelo_consumo_energia-> lista_campus控制器();

但是沒有分配任何變量......所以沒有結果。

我建議去調試簡單的事情,看在哪個部位,代碼不能正常工作,因爲我想你剛纔寫這些東西,然後它是不可能知道發生了什麼。

您正在使用MVC,拿那個!似乎是模型的作品,現在試圖驗證控制器和視圖工作太寫了簡單的代碼,像回聲的東西...