【问题标题】:Ignited+datatables -> order by点燃+数据表->按顺序
【发布时间】:2014-09-29 03:37:54
【问题描述】:

我正在使用带有数据表的 codeigniter,我想按列排序。

我该怎么做?

$this->datatables->select('col_1, col_2, col_3');
$this->datatables->from('table');

....$this->datatables->order ?!?

谢谢

【问题讨论】:

    标签: codeigniter datatables


    【解决方案1】:

    使用:

    $this->db->order_by("column name", "desc");
    

    【讨论】:

    • 是的,它有效。多谢兄弟。我一直在寻找数据表函数。
    • 它确实适用于数据表,但是当您使用数据表时,它有自己的列顺序。它会给出错误。它将保持在顶部,其余字段会上下波动,这会使记录变差:(
    【解决方案2】:

    您可以在初始化时使用 aaSorting 参数对表格进行排序。

    $(document).ready( function() {
      $('#example').dataTable( {
        "aaSorting": [[2,'asc'], [3,'desc']]
      } );
    } );
    

    其中 2 和 3 是列的索引

    【讨论】:

      【解决方案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;}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多