我的问题是关于我的特定货币类型的分类 我有以下类型的货币:
这是我整个数据库表中的第5行,因此
我需要能够对数据表的价格进行排序,我被告知这样可行:
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"currency-pre": function (a) {
a = (a === "-") ? 0 : a.replace(/[^\d\-]/g, "");
return parseFloat(a);
},
"currency-asc": function (a, b) {
return a - b;
},
"currency-desc": function (a, b) {
return b - a;
}
});
但是,这在我的情况下不起作用。
我有两个可能的数据表初始化结果:
$('table').dataTable( {
"aoColumns": [{"sType": "currency"}],
"order": [[ 0, "desc" ]],
"columnDefs": [
{ "type": "de_datetime", targets: 0 },
{ "orderable": false, "targets": 2 },
{ "type": "currency", targets: 5 }
],
stateSave: true
} );
以及
$('table').DataTable( {
"ajax": "<?php echo SCRIPT_URL; ?>api/admin_overview_quotations_json.php",
"columns": [
{ "data": "post_time" },
{ "data": "number" },
{ "data": "company" },
{ "data": "reference" },
{ "data": "total_price" },
{ "data": "status" },
{ "data": "sales_call_date" },
{ "data": "quotation_id" }
],
"order": [[ 0, "desc" ]],
"columnDefs": [
{ "type": "de_datetime", targets: 0 },
{ "type": "de_datetime", targets: 6 },
{ "orderable": false, "targets": 1 },
{ "render": function ( data, type, row ) {
return '<a type="button" class="btn btn-primary view_by_id hidden-xs hidden-md" href="#" data-toggle="modal" data-target="#view" data-url=<?php echo SCRIPT_URL; ?>api/admin_download_quotation.php?quotation_id=' + data + '&action=view" data-tooltip="tooltip" data-placement="top" title="<?php echo ASLang::get('View offer'); ?>"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></a> <a type="button" class="btn btn-primary" href="<?php echo SCRIPT_URL; ?>admin/new-project.php?type=offer&id=' + data + '&action=manage" data-tooltip="tooltip" data-placement="top" title="<?php echo ASLang::get('Edit offer'); ?>"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></a> <a type="button" class="btn btn-primary" href="<?php echo SCRIPT_URL; ?>admin/new-project.php?type=offer&id=' + data + '&action=order" data-tooltip="tooltip" data-placement="top" title="<?php echo ASLang::get('Make order from offer'); ?>"><i class="icon-basket"></i></a> <a type="button" class="btn btn-primary hidden-xs hidden-md" href="<?php echo SCRIPT_URL; ?>api/admin_download_quotation.php?quotation_id=' + data + '&action=download" data-tooltip="tooltip" data-placement="top" title="<?php echo ASLang::get('Download quotation'); ?>"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span></a> <a type="button" class="btn btn-primary visible-xs visible-md" href="<?php echo SCRIPT_URL; ?>api/admin_download_quotation.php?quotation_id=' + data + '&action=view" target="_blank" data-tooltip="tooltip" data-placement="top" title="<?php echo ASLang::get('View offer'); ?>"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></a>';
},
"targets": 7
}
],
stateSave: true,
"language": {
"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Dutch.json"
}
} );
取决于具体的常数,但事实仍然是需要对价格进行分类。
这当然是我的问题。为什么排序不起作用?我已尝试登录oSort的扩展名,但点击时也不会记录。
我也尝试了以下正则表达式:
(/[^\d\-]/g
[^\d\-]
但这也无济于事。