Datatable icon indicating copy to clipboard operation
Datatable copied to clipboard

can't have custom string values and still sort as integer

Open andrewhl opened this issue 10 years ago • 1 comments

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?

andrewhl avatar Dec 02 '14 20:12 andrewhl

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.

schir1964 avatar Dec 19 '14 04:12 schir1964