【发布时间】:2014-09-29 03:37:54
【问题描述】:
我正在使用带有数据表的 codeigniter,我想按列排序。
我该怎么做?
$this->datatables->select('col_1, col_2, col_3');
$this->datatables->from('table');
....$this->datatables->order ?!?
谢谢
【问题讨论】:
我正在使用带有数据表的 codeigniter,我想按列排序。
我该怎么做?
$this->datatables->select('col_1, col_2, col_3');
$this->datatables->from('table');
....$this->datatables->order ?!?
谢谢
【问题讨论】:
使用:
$this->db->order_by("column name", "desc");
【讨论】:
您可以在初始化时使用 aaSorting 参数对表格进行排序。
$(document).ready( function() {
$('#example').dataTable( {
"aaSorting": [[2,'asc'], [3,'desc']]
} );
} );
其中 2 和 3 是列的索引
【讨论】:
您可以使用这种方式,我在这里使用 codeigniter DATA-TABLE 和 MYSQL select 控制所有必需的值,包括一个小连接
function get_ComponentList($rowperpage, $row, $search='',$order, $dir)
{
$this->db->select('a.component_id, a.component_name as component_name, a.eco_code as eco_code, b.component_name as parent_name');
$this->db->from('component_info as a');
$this->db->join('component_info as b', 'b.component_id = a.parent_id', 'left');
$this->db->order_by($order,$dir);
if($search != ''){
$this->db->like('a.component_name', $search);
$this->db->or_like('a.eco_code', $search);
$this->db->or_like('b.component_name', $search);
}
$this->db->limit($rowperpage,$row);
$query = $query->result();
return $query;}
【讨论】: