Datatables 的自然排序插件在服务器端处理获得数据的地方工作吗? [英] Does Datatables' natural sort plugin work where data is got with server side processing?

查看:10
本文介绍了Datatables 的自然排序插件在服务器端处理获得数据的地方工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让它处理静态 html 数据,如这个 jsfiddle 所示:

I got it to work with static html data as shown in this jsfiddle:

http://jsfiddle.net/L7PNV/

通过指定

aoColumns: {"sType": "natural"}

当我对第一列进行排序时,它以正确(自然排序)的顺序显示行:

where when I sort the first column it shows rows in right (natural-sorted) order:

SIR_1_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1    
SIR_2_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1    
SIR_3_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1    
SIR_10_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1
...

但后来我想对同一个数据表应用自然排序,其中数据是在服务器端获取的,我调用数据表的代码与在 jsfiddle 中添加服务器端相关内容的代码相同:

But then I want to apply natural sort to this same datatable where data is fetched server-side, the code where I invoke the data table is the same as in the jsfiddle adding the serverside related things:

$ -> 
  $("#sir_table").dataTable
    sPaginationType: "full_numbers"
    bProcessing: true
    bServerSide: true
    aoColumns: [{"sType": "natural"}, {"sType": "natural"}, {"sType": "natural"} ]
    aaSorting: [[ 1, "asc" ]]
    sAjaxSource: $('#sir_table').data('source')

DataTable 显示正常,但自然排序无法正常工作(就像在 jsfiddle 中一样,如上所述).而是显示行:

The DataTable shows alright but the natural-sort does not work as it should (like in the jsfiddle, as above). Instead rows are displayed:

SIR_1_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1    
SIR_10_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1
... 
SIR_19_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1
SIR_2_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1
SIR_20_SIL_CGG_2011_224_SILAC1b_IMAC_Fr1

为什么会这样?自然排序插件甚至与服务器端处理兼容吗?我应该如何实施?

Why is this happening? Is natural-sort plugin even compatible with server side processing? How should I implement it?

推荐答案

只需修改'ssp.class.php中的'静态函数顺序( $request, $columns )'函数':

Just modify the 'static function order ( $request, $columns )' function in 'ssp.class.php':

if ( $column['db'] == 'Nr' ) {
    // Natural Sort
    $orderBy[] = 'LENGTH(`' . $column['db'] . '`) ' . $dir . ', ' . '`' . $column['db'] . '` ' . $dir;
} else {
    $orderBy[] = '`' . $column['db'] . '` ' . $dir;
}

从现在起,名为Nr"的列将进行自然排序.

From now on the column with the name 'Nr' will have natural sort.

这篇关于Datatables 的自然排序插件在服务器端处理获得数据的地方工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆