说实话,我对代码的处理方式一无所知,我一直在做这些事情,'读这个和那个,并没有结果。我仍然是编程的新手。主要问题是Ignited-Datatable 2.0 beta和Datatables 1.10.12我使用的是MVC模式,我在此看到了CV模式。
这是我尝试以点火风格制作的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;
}
它有效,但需要以Datatables方式排序。尝试这样的事情Stack Example,但没有结果。
所以...这是我的点燃数据表“尝试”模型
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 :(得分:0)
很难回答所有问题......但我看到的可能是错误:
在控制器中调用函数
$这 - &GT; modelo_consumo_energia-&GT; lista_campus();
但是没有在任何变量中分配......所以没有结果。
我建议调试简单的事情,看看代码在哪个部分,代码不起作用,因为我想你只是写了所有这些东西,然后就不可能知道发生了什么。
你正在使用MVC,拿走它!看起来像模型工作,现在尝试验证控制器和视图正在编写简单的代码,如回声... ...