I have an address field in my table which is showing but the sorting is by default done with numbers first, i want to ignore numbers and make sure the sorting should go with alphabets, i am checking everywhere but does not seems to work
Here is some kind of sample i am trying with integers, can anyone show some code with alphabets only
jQuery.fn.dataTableExt.oSort['intComparer-asc'] = function (a, b) {
var m = a.match(/^\<.*\>(\d+)\<.*\>/);
a = m[1];
var m = b.match(/^\<.*\>(\d+)\<.*\>/);
b = m[1];
var value1 = parseInt(a);
var value2 = parseInt(b);
return ((value1 < value2) ? -1 : ((value1 > value2) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['intComparer-desc'] = function (a, b) {
var m = a.match(/^\<.*\>(\d+)\<.*\>/);
a = m[1];
var m = b.match(/^\<.*\>(\d+)\<.*\>/);
b = m[1];
var value1 = parseInt(a);
var value2 = parseInt(b);
return ((value1 < value2) ? 1 : ((value1 > value2) ? -1 : 0));
};
$(document).ready(function() {
$('#my_datatable').each( function(){
oTable = $(this).dataTable({
'bPaginate': false,
'bInfo': false,
'bFilter': false,
'aoColumnDefs': [
{ 'sType': 'intComparer', 'aTargets': [ 0, 1 ] }
]
});
});
});
Tried it like this
jQuery.fn.dataTableExt.oSort['stringComparer-asc'] = function (a, b) {
var m = a.match(/^[a-zA-Z]+$/);
a = m[1];
var m = b.match(/^[a-zA-Z]+$/);
b = m[1];
var value1 = a;
var value2 = b;
return ((value1 < value2) ? -1 : ((value1 > value2) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['stringComparer-desc'] = function (a, b) {
var m = a.match(/^[a-zA-Z]+$/);
a = m[1];
var m = b.match(/^[a-zA-Z]+$/);
b = m[1];
var value1 = parseInt(a);
var value2 = parseInt(b);
return ((value1 < value2) ? 1 : ((value1 > value2) ? -1 : 0));
};
oTable = $('#table').dataTable( {
"bStateSave": true,
"bProcessing": true,
"iDisplayLength": 15,
"aoColumns": [
null,
{"sType": "stringComparer"},
null,
null,
null,
null,
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false }
],
} );
But got an error:
TypeError: m is null
a = m[1];