Datatables的自然排序插件可以在服务器端处理数据的情况下工作吗? [英] Does Datatables' natural sort plugin work where data is got with server side processing?
问题描述
我得到它使用静态html数据,如这个jsfiddle所示:
I got it to work with static html data as shown in this jsfiddle:
通过指定
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?
推荐答案
只需修改静态函数顺序($ request,$ columns) ' ssp.class.php '中的strong>'函数:
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屋!