Datatable
Datatable copied to clipboard
can't have custom string values and still sort as integer
I've got a column that returns an integer. I'm trying to concatenate it with a $ to represent currency.
In my controller I am using a FunctionColumn object, and passing this to the Datatable::collection.
$amount_column = new FunctionColumn('amount', function($row) {
return '<span>$' . $row->amount . '</span>';
});
I am also calling setOrderStrip() on the collection with the 'amount' column as the parameter.
->setOrderStrip('amount')
The column renders in the view but is not sortable by number. It sorts as a string. How can I get the Datatable to ignore the '$' and treat the column as an integer for the purposes of sorting?
One way is to put just the integer into a "hidden" column and then direct the sort mechanism to sort on the hidden column instead of the string display column.