jQuery - datatable插件 - 排序问题 [英] jQuery - datatable plugin - sorting issue

查看:436
本文介绍了jQuery - datatable插件 - 排序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://datatables.net 中的DataTables插件。

插件自己是非常有用的,但我有一个很大的问题。

I'm using DataTables plugin from http://datatables.net.
The plugin it self is very useful,but I have a big of a problem with it.

它以一种以下格式返回一些搜索的地址列表。 p>

It is return a list of address for some searches in the following format.

1 Main Street
12 Main Street
13 Main Street
14 Main Street
...
2 Main Street
3 Main Street
4 Main Street
5  Main Street
..

正如你可以看到排序不是我所期望的。将从 1开始的所有数字,例如11,111,1111 之前 2

As you can see the sorting is not what I would expected. Will return all numbers starting with 1 eg, 11, 111, 1111 before 2.

有没有人有插件的一些有效期?

Have any of you have some expirience with the plugin?


  • 知道解决这个排序问题?

  • 或者知道首先禁用排序的方式启动(以数据形式显示数据)?

任何建议都非常感激。

推荐答案

要解决这个特殊问题,可以使用natural-sort plugin来进行数据表。请阅读 http://datatables.net/plug-ins/sorting 的全部信息(搜索自然排序)。

To solve this particular issue you can use natural-sort plugin for datatables. Read all about it at http://datatables.net/plug-ins/sorting (search for "Natural sorting").

简而言之,提供你已经下载了并嵌入了 naturalSort 函数,然后为数据表定义排序句柄像这样:

In short, provided you've downloaded and embedded naturalSort function, you then define sort handle for datatables like this:

jQuery.fn.dataTableExt.oSort['natural-asc']  = function(a,b) {
    return naturalSort(a,b);
};

jQuery.fn.dataTableExt.oSort['natural-desc'] = function(a,b) {
    return naturalSort(a,b) * -1;
};

您还需要为列指定sSortDataType参数,告诉它哪个插件功能使用(在下面的例子中,我将排序设置为自然表格的第三列):

You also need to specify the sSortDataType parameter for the column, to tell it which plug-in function to use (in example below I set the sorting to natural for the third column of my table):

$('#example').dataTable( {
    "aoColumns": [
        null,
        null,
        { "sType": "natural" }
]
});

这里是工作小提琴 http://jsfiddle.net/zhx32/14/

Here's working fiddle http://jsfiddle.net/zhx32/14/

注意:似乎你其实在aoColumns上的元素数量必须等于表中的列数,否则你会得到一个错误。空值表示数据插件应该为该列使用默认排序方法。

这篇关于jQuery - datatable插件 - 排序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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