Nepali numbers

Sorts columns containing UTF8 nepali numbers

  • Author: [david konrad](davidkonrad at gmail com)

Sorts a column containing nepali numbers. Nepali numbers can easily be mapped 1:1 to latin numbers - १ = 1, २ = 2, १२ = 12 and so on.

https://en.wikipedia.org/wiki/Numbers_in_Nepali_language http://www.imnepal.com/nepali-numbers http://stackoverflow.com/q/26856481/1407478 http://jsfiddle.net/ft7f16yt

Plug-in code

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "nepali-numbers-pre" : function(a) {
        function nepaliToLatin(nepali) {
            switch(nepali) {
                case "०": return 0; break;
                case "१": return 1; break;
                case "२": return 2; break;
                case "३": return 3; break;
                case "४": return 4; break;
                case "५": return 5; break;
                case "६": return 6; break;
                case "७": return 7; break;
                case "८": return 8; break;
                case "९": return 9; break;        
                default : return 0; break;
            }        
        }
        var latin = '', i = 0;
        for (i; i<a.length; i++) {
            latin += nepaliToLatin(a.charAt(i))
        }
        return parseInt(latin)
    },

    "nepali-numbers-asc": function(a, b) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0))
    },

    "nepali-numbers-desc": function(a, b) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0))
    }

} );

CDN

This plug-in is available on the DataTables CDN:

JS

Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.

Version control

If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!

Example

$('#example').DataTable( {
     columnDefs: [
       { type: 'nepali-numbers', targets: 0 }
     ]
  } );