Case-Sensitive
Sort based on case of data, In ascending order capitals are prioritised over lower case.
- Author: Sandy Galloway
This plug in will sort data taking into account upper and lower case. In ascending order it will prioritise upper case letters, before continuing to the lower case letters.
Plug-in code
jQuery.extend(jQuery.fn.dataTableExt.oSort,{
"case-sensitive-asc": function(a,b){
if(a<b){
return -1;
} else if(a>b){
return 1;
} else{
return 0;
}
},
"case-sensitive-desc": function(a,b){
if(a>b){
return -1;
} else if(a<b){
return 1;
} else{
return 0;
}
}
});
CDN
This plug-in is available on the DataTables CDN:
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!
- This plug-in: Case-Sensitive.js
- Full DataTables plug-ins repository: DataTables/Plugins
Example
//This example shows how to invoke the case-sensitive plugin on the first column.
//It will sort the data in alphabetical order Prioritising the capital letters to take
//a form similair to [A,B,C,D,...,a,b,c,d,...] for ascending order.
$(document).ready( function () {
var table = $('#example').DataTable({
"columnDefs": [
{"type": "case-sensitive",targets:0}
]
});
} );