Ketan Akbari
Ketan Akbari

Reputation: 11287

How to do a custom sorting in datatables?

Is it possible to sort numeric item according to its values in a column which contains both numeric and string items in datatables?

I tried columnDefs:

[{ type: 'natural', targets: [0,1] }] 

But it's not working. Any help is appreciated.

Upvotes: 1

Views: 6924

Answers (1)

davidkonrad
davidkonrad

Reputation: 85578

Well, perhaps you just need to see a working example? Here is the values from the other question you are referring to, and the usage of a sorting plugin I once made for exactly this, any-number -> https://github.com/davidkonrad/Plugins/blob/master/sorting/any-number.js

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

see how it is working here -> http://jsfiddle.net/o53burrf/ This is how most of the other sorting plugins works as well - if you want to use natural, include the source snippet an replace any-number with natural.

Upvotes: 4

Related Questions