简体   繁体   English

自然排序 Ajax Codeigniter 中的数据表

[英]Natural sorting Ajax Datatables in Codeigniter

Struggling to figure out how to set natural sorting in AJAX Datatables using Codeigniter Active record.努力弄清楚如何使用 Codeigniter 活动记录在 AJAX 数据表中设置自然排序。 The field that should be sorted has, in most cases, just digits...in other cases a string, so the MySQL table field is set as VARCHAR.在大多数情况下,应该排序的字段只有数字……在其他情况下是字符串,因此 MySQL 表字段设置为 VARCHAR。

I need to srt naturally the field to be displayed in Datatables.我需要自然地 srt 要在 Datatables 中显示的字段。

The Active record Codeigniter query is the following.活动记录 Codeigniter 查询如下。

function list_all($limit,$start,$col,$dir)
{   
    $this->rmi_db->select (" 
        $this->table_dev.id,
        $this->table_dev.fl,
        $this->table_dev.mm,
        $this->table_dev.batch,
        $this->table_dev.n,
        $this->table_dev.ditta,
        $this->table_dev.tipo,
        $this->table_dev.costruzione,
        $this->table_dev.motori,
        $this->table_dev.nc,
        $this->table_dev.serie,
        $this->table_dev.ca,
        $this->table_dev.consegna,
        $this->table_dev.matr_usaf AS usaf,
        $this->table_dev.matr_usn AS usn,
        $this->table_dev.matr_caf AS caf,
        $this->table_dev.matr_raf AS raf,
        $this->table_dev.codici,
        $this->table_dev.note,
        $this->table_dev.reg_civili,
        $this->table_dev.matricola_civ,
        $this->table_dev.prima_reg,
        $this->table_dev.n_contratto,
        $this->table_dev.data_contratto,
        $this->table_dev.importo_contratto,
        $this->table_dev.note_contratto,
        $this->table_dev.f29,
        $this->table_dev.f30,     
        ");
    $this->rmi_db->from("$this->table_dev");
    $this->rmi_db->where("$this->table_dev.mm !=", "");
    $this->rmi_db->limit($limit, $start);
    $this->rmi_db->order_by($col, $dir);
    $query = $this->rmi_db->get();

    if($query->num_rows()>0)
    {
        return $query->result(); 
    }
    else
    {
        return null;
    }
}

The mm field should be sorted naturally. mm字段应该自然排序。 I have no idea how and if it's possible to fix the issue.我不知道如何以及是否可以解决这个问题。 I tried the solution in this discussion solutions , the Bin way, but the select doesn't work properly ( got 500 server error)我尝试了此讨论解决方案中的解决方案,即 Bin 方式,但 select 无法正常工作(出现 500 服务器错误)

Thanks a lot for any help非常感谢您的帮助

Using Solution , Try below.使用解决方案,试试下面。 It should work but not tested.它应该可以工作但未经测试。

function list_all($limit,$start,$col,$dir)
{   
$this->rmi_db->select (" 
    $this->table_dev.id,
    $this->table_dev.fl,
    $this->table_dev.mm,
    $this->table_dev.mm, CAST($this->table_dev.mm as SIGNED) AS casted_column,//changed
    $this->table_dev.batch,
    $this->table_dev.n,
    $this->table_dev.ditta,
    $this->table_dev.tipo,
    $this->table_dev.costruzione,
    $this->table_dev.motori,
    $this->table_dev.nc,
    $this->table_dev.serie,
    $this->table_dev.ca,
    $this->table_dev.consegna,
    $this->table_dev.matr_usaf AS usaf,
    $this->table_dev.matr_usn AS usn,
    $this->table_dev.matr_caf AS caf,
    $this->table_dev.matr_raf AS raf,
    $this->table_dev.codici,
    $this->table_dev.note,
    $this->table_dev.reg_civili,
    $this->table_dev.matricola_civ,
    $this->table_dev.prima_reg,
    $this->table_dev.n_contratto,
    $this->table_dev.data_contratto,
    $this->table_dev.importo_contratto,
    $this->table_dev.note_contratto,
    $this->table_dev.f29,
    $this->table_dev.f30,     
    ");
$this->rmi_db->from("$this->table_dev");
$this->rmi_db->where("$this->table_dev.mm !=", "");
$this->rmi_db->limit($limit, $start);
$this->rmi_db->order_by($col, $dir);
$this->rmi_db->order_by('casted_column', 'ASC'); // changed
$this->rmi_db->order_by($this->table_dev.mm, 'ASC'); // changed
$query = $this->rmi_db->get(); //changed

if($query->num_rows()>0)
{
    return $query->result(); 
}
else
{
    return null;
}
}

comment if you face any issue如果您遇到任何问题,请发表评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM