在jQuery DataTables中使用锚标记对列进行排序

sha*_*haz 1 sorting jquery datatables

我使用jQuery数据表插件对表数据进行排序.如果列包含简单文本,则排序工作正常.如果我在文本上放置任何锚标记条件,则列排序不能正确排序.

我以下列方式显示了这些值:

<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>
Run Code Online (Sandbox Code Playgroud)

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

TMN*_*ear 5

在ready函数之前添加:

    //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));
    };
Run Code Online (Sandbox Code Playgroud)

并在准备功能:

        "aoColumns": [
          { "sType": "num-html" },
          null,
          etc. etc.
        ]
Run Code Online (Sandbox Code Playgroud)

这是锚定器对我有用的方式,整数按照它们的顺序排列.