在将 JQuery 库 DataTables 与 jquery.dataTables.yadcf 一起使用时,我们遇到了一个大问题:当我们想要选择值“零”时,排序不起作用,例如在关注秒延迟的列中。但如果我们添加另一个值,两者就会排序!
有人知道这是否正常或者我们是否可以找到解决方案来避免它?
$('#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
}
]);