Hi
I am struggling to get the DataGrid to sort numbers correctly. As you can see from the screenshot, sorting by amount_invoiced sorts as a string, not as a number. This 123.00 sorts before 2.00.
I have tried various options to work round the issue but none seem to work.
DataTables::create([
"dataSource"=>$report->dataStore("unpaidInvoices"),
"columns"=>[
"invoice_no" => [
"label" => "Invoice No.",
"type"=>"number",
],
"invoice_dt" => [
"label" => "Invoice Date",
"data-order" => "raw_invoice_dt",
],
"customer_name" => [
"label" => "Customer",
],
"amount_invoiced"=>[
"label" => "Amount Invoiced",
"type"=>"number",
"decimals"=>2,
],
"amount_paid"=>[
"label" => "Amount Paid",
"type"=>"number",
"decimals"=>2,
],
"amount_owing"=>[
"label" => "Amount Owing",
"type"=>"number",
"decimals"=>2,
],
"due_dt" => [
"label" => "Payment Due",
"data-order" => "raw_due_dt",
],
"status" => [
"label" => "Status",
],
"raw_invoice_dt",
"raw_due_dt",
],
"options" => [
"searching"=>true,
"paging"=>true,
],
"cssClass" => [
"th" => function ($colName) {
if (substr($colName,0,6)=="amount") {
return "text-right";
} elseif (substr($colName,0,3)=="raw") {
return "d-none";
}
},
"td" => function ($row,$colName) {
if (substr($colName,0,6)=="amount") {
return "text-right";
} elseif (substr($colName,0,3)=="raw") {
return "d-none";
}
},
]
]);
Any help would be appreciated.
Thanks Nick