在 JQuery DataTables YADCF 中对值零进行排序不起作用

问题描述 投票:0回答:1

在将 JQuery 库 DataTables 与 jquery.dataTables.yadcf 一起使用时,我们遇到了一个大问题:当我们想要选择值“零”时,排序不起作用,例如在关注秒延迟的列中。但如果我们添加另一个值,两者就会排序!

有人知道这是否正常或者我们是否可以找到解决方案来避免它?

yadcf
1个回答
0
投票
$('#example').DataTable({
    columnDefs: [
        {
            targets: 0, // Adjust the target index based on your column
            type: 'num' // Ensure the column is treated as numeric
        }
    ]
});



$.fn.dataTable.ext.order['num-asc'] = function (settings, col) {
    return this.api()
        .column(col, { order: 'index' })
        .data()
        .map(function (value) {
            return value === '0' ? -Infinity : parseFloat(value);
        });
};

$.fn.dataTable.ext.order['num-desc'] = function (settings, col) {
    return this.api()
        .column(col, { order: 'index' })
        .data()
        .map(function (value) {
            return value === '0' ? Infinity : parseFloat(value);
        });
};

$('#example').DataTable({
    columnDefs: [
        { targets: 0, orderDataType: 'num' }
    ]
});



yadcf.init($('#example').DataTable(), [
    {
        column_number: 0, // Set your correct column number
        filter_type: 'range_number' // Adjust filter type if needed
    }
]);
© www.soinside.com 2019 - 2024. All rights reserved.