gpt4 book ai didi

jquery - 在 jQuery DataTables 中使用 anchor 标记对列进行排序

转载 作者:行者123 更新时间:2023-12-01 06:16:28 26 4
gpt4 key购买 nike

我使用 jQuery 数据表插件对表数据进行排序。如果列包含简单文本,排序效果很好。如果我在文本上放置任何 anchor 标记条件,则列排序将无法正确排序。

我通过以下方式显示值:

<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>

使用此代码,列排序失败。

最佳答案

在就绪函数之前添加此内容:

    //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.
]

这就是我使用 anchor 的工作方式,整数按其应有的方式排序。

关于jquery - 在 jQuery DataTables 中使用 anchor 标记对列进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1899500/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com