在jQuery DataTables中使用锚标记对列进行排序 [英] Sorting column with anchor tags in jQuery DataTables
本文介绍了在jQuery DataTables中使用锚标记对列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery datatable插件对表数据进行排序.如果一列包含简单文本,则排序工作正常.如果我在文本上放置任何锚标记条件,则列排序将无法正确排序.
I used the jQuery datatable plugin in sort the table data. The sorting works fine if a column contains simple text. If I put any anchor tag condition on a text then the column sorting does not sort properly.
我以以下方式显示值:
<td><?php if ($allAptArr[$d][27]['staffinactive'] == 1) { ?>
<?=ucwords(stripslashes($allAptArr[$d][5]['staff_name']));?>
<?php } else { ?>
<a href='#' onClick="redirectToStaff('<?=$allAptArr[$d][10]['staff_id']?>');">
<?=ucwords(stripslashes($allAptArr[$d][5]['staff_name']));?>
</a>
<?php } ?> </td>
使用此代码,列排序失败.
with this code the column sorting fails.
推荐答案
将其添加到ready函数之前:
add this before the ready function:
//sets up numeric sorting of links
jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
var x = a.replace( /<.*?>/g, "" );
var y = b.replace( /<.*?>/g, "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y || isNaN(y) ) ? -1 : ((x > y || isNaN(x)) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
var x = a.replace( /<.*?>/g, "" );
var y = b.replace( /<.*?>/g, "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y || isNaN(x)) ? 1 : ((x > y || isNaN(y) ) ? -1 : 0));
};
以及就绪功能:
"aoColumns": [
{ "sType": "num-html" },
null,
etc. etc.
]
这是锚点对我的工作方式,整数按其应有的顺序排序.
This is how it works for me with anchors, integers are getting ordered as they should.
这篇关于在jQuery DataTables中使用锚标记对列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文