Sorting alpha-numeric data with jQuery DataTables

2019-05-10 06:16发布

问题:

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?

回答1:

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.