Formating numbers with datatables as a service #2620
Unanswered
EnriqueRBT
asked this question in
Q&A
Replies: 3 comments
-
Try this: Column::make('cost')->title('Coste')->renderJs('number', '.',',','4','',' €') Or Column::make('cost')->title('Coste')->renderRaw("$.fn.dataTable.render.number('.',',','4','',' €')") |
Beta Was this translation helpful? Give feedback.
0 replies
-
Another newer way is via server-side formatters. public function dataTable($query)
{
return datatables()
->eloquent($query)
->formatColumn('amount', MoneyFormatter::class)
->setRowId('id');
}
protected function getColumns()
{
return [
Column::make('id'),
Column::formatted('amount'), Formatter Class: namespace App\DataTables\Formatters;
use Yajra\DataTables\Contracts\Formatter;
class MoneyFormatter implements Formatter
{
public function format($value, $row)
{
return number_format($value, 2);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you very much, you are really kind, and the second message is really useful for me that i'm learning. I trully apreciate it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to format the price to european currency. It,s easy with datatables helpers as explained in: https://datatables.net/manual/data/renderers#Built-in-helpers
For exmaple:
{data: 'cost', render:$.fn.dataTable.render.number('.',',','4','',' €'), name: 'cost'},
The problem is if I use datatables as a service. I can`t find any documentation about how to achieve this.
` protected function getColumns()
............`
Thanks for helping.
Beta Was this translation helpful? Give feedback.
All reactions