在客户端处理模式下使用jQuery DataTables对字母数字数据进行排序 [英] Sorting alpha-numeric data with jQuery DataTables in client side processing mode

查看:95
本文介绍了在客户端处理模式下使用jQuery DataTables对字母数字数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个有字母数字值的表格,例如:

  8980 
1100
A1100
BA200

我希望它先按数字顺序排序,然后以字母数字方式,例如

  1000 
8980
A1100
BA200

在这里找到了一些帮助,但不是我正在寻找的东西: http://datatables.net/forums/discussion/367/bug-sort-number-column-and- stype



有没有一种方法可以使用任何API来实现这一点?

解决方案


解决方案 blockquote>

使用自然排序插件例如,使用下面的代码对第一列进行排序( targets:0 ),

  var table = $('#example')。DataTable(code>)使用自然排序插件。 {
columnDefs:[{targets:0,type:'natural'}]
});

不要忘记包含插件 JavaScript文件


DEMO


请参阅这个jsFiddle 用于代码和演示。


So I have a table that have alpha-numeric values for example:

8980
1100
A1100
BA200

I want it to sort it in a numeric order fashion first and then in alpha-numeric fashion e.g.

1000 
8980
A1100
BA200

Found some help here but not exactly the thing I am looking for: http://datatables.net/forums/discussion/367/bug-sort-number-column-and-stype

Is there a way to achieve this using any API?

解决方案

SOLUTION

Use Natural sorting plug-in to sort data with a mix of numbers and letters naturally.

For example, use the code below to sort first column (targets: 0) using natural sorting plug-in.

var table = $('#example').DataTable({
   columnDefs: [ { targets: 0, type: 'natural' } ]    
});

Don't forget to include plug-in JavaScript file.

DEMO

See this jsFiddle for code and demonstration.

这篇关于在客户端处理模式下使用jQuery DataTables对字母数字数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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