JQuery DataTables 列自己定义数据类型排序

使用JQ DataTables 的时候。希望某列数据能够进行自己定义排序。操作例如以下:(以中文排序和百分比排序为例)

1:定义排序类型:

//百分率排序
jQuery.fn.dataTableExt.oSort['number-fate-asc']  = function(s1,s2) {
	s1 = s1.replace('%','');
	s2 = s2.replace('%','');
	return s1-s2;
};

jQuery.fn.dataTableExt.oSort['number-fate-desc'] = function(s1,s2) {
	s1 = s1.replace('%','');
	s2 = s2.replace('%','');
	return s2-s1;
};
//中文排序
jQuery.fn.dataTableExt.oSort['chinese-string-asc']  = function(s1,s2) {
	return s1.localeCompare(s2);
};
jQuery.fn.dataTableExt.oSort['chinese-string-desc'] = function(s1,s2) {
	return s2.localeCompare(s1);
}; 


2:指定排序的列:

$('#flexme1').dataTable({
	"aoColumns": [
		null,
		{ "sType": "chinese-string" },//中文排序列
		null,
		{ "sType": "number-fate" },//百分率排序
		null,
		null
	]
}); 


posted @ 2017-06-28 20:26  llguanli  阅读(1330)  评论(0编辑  收藏  举报