我有一张包含大量百分比的表格。我使用DataTables对我的大部分表格进行排序,如果您在此处检查最右边的列,则基于文本的百分比确实可以正确排序。
问题是......我想删除它并将其替换为左侧的 CSS 条(最右边的第二列)。我根本无法使用 DataTables 对这些 CSS 条进行排序。
这是我在每个<td>...中使用的代码
<div id="positive">
    <div class="anim" style="width:27%;">
        <div class="text">27.05%</div>
    </div>
</div>
我使用HERE的百分比部分中的代码来获取要在最右侧列排序的百分比。
知道如何让 DataTables 忽略上面代码中的所有 HTML 标签并仅按百分比排序吗?
感谢您提供的任何帮助,如果您需要更多信息,请告诉我。
EDIT1:这是用于对文本百分比进行排序的代码
    jQuery.extend( jQuery.fn.dataTableExt.oSort, 
        {
        "percent-pre": function ( a ) 
            {
            var x = (a == "-") ? 0 : a.replace( /%/, "" );
            return parseFloat( x );
            },
        "percent-asc": function ( a, b ) 
            {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },
        "percent-desc": function ( a, b ) 
            {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        } );
以下是我在该页面上用于数据表的选项(如果需要,我可以更改内容)。
编辑2:
    $(document).ready(function() 
        {
        $('#gradient-style').dataTable( 
            {
            "bPaginate": true,
            "aaSorting": [[ 7, "desc" ]],
            "bJQueryUI": true,
            "aLengthMenu": [[50, 100, 200, -1], [50, 100, 200, "All"]],
            "iDisplayLength": 50,
            "sPaginationType": "full_numbers",
            "sDom": '<"H"lf>rt<"F"ip>',
            "aoColumnDefs": [ { "bVisible": false, "aTargets": [ 0, 6 ] } ],
            "aoColumns": [
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            { "sType": "percent" },
            { "sType": "percent" } ]
            } );
        } );
EDIT3:解决了
这就是我所做的...转到此页面。Numbers with HTML与合并 
Percentage。这是我在 edit1 代码中更改的代码。
            /* This cuts out the HTML */
            var x = String(a).replace( /<[\s\S]*?>/g, "" );
            return parseFloat( x );
            /* This takes what's left, removes the % sign and sorts by that */
            var y = (x == "-") ? 0 : x.replace( /%/, "" );
            return parseFloat( y );