Money Column
Format currency amounts with ISO 4217 codes, cents storage, and locale-aware display
MoneyColumn formats numeric amounts as money on the client. It uses the DataTables num type so
sorting stays numeric while display uses Intl.NumberFormat.
Defaults: currency EUR, values stored as cents, 2 decimal places, currency sign shown.
Basic Usage
use Pentiminax\UX\DataTables\Column\MoneyColumn;
MoneyColumn::new('price', 'Price');
Currency And Storage
MoneyColumn::new('total', 'Total')
->currency('USD')
->storedAsCents(true)
->decimals(2);
MoneyColumn::new('rate', 'Rate')
->currency('EUR')
->storedAsCents(false)
->showCurrencySign(false);
Pass an ISO 4217 code to currency() (three letters). When storedAsCents(true) (the default),
the stored integer is divided by 10^decimals before display: 12345 with the default two
decimals shows as €123.45, and 12345 with decimals(3) shows as 12.345. When false, the
raw number is formatted as-is.
In The Edit Modal
The edit form maps a money column to Symfony’s MoneyType with the column’s currency and decimals.
A column stored as cents is edited in whole currency units using the same 10^decimals scale as the
table: 2500 opens as 25.00, and saving 30.5 stores 3050. A column stored as whole units is
bound as entered.
The form converts through floating-point numbers, so a column stored as cents with more than eight decimals (an 18-decimal token amount, for instance) is left out of the edit form: opening and saving it would round the stored integer. Edit such a column with your own form.
API Reference
| Method | Description |
|---|---|
MoneyColumn::new(string $name, string $title = '') | Creates a MoneyColumn (type: num, isMoney: true) |
currency(string $currency) | ISO 4217 currency code (default: EUR) |
storedAsCents(bool $storedAsCents = true) | Divide by 10^decimals before display and in the edit form when true (default) |
decimals(int $decimals) | Fraction digits and cents scale (0–20, default: 2) |
showCurrencySign(bool $show = true) | Use currency style vs plain decimal formatting |
Complete Example
use Pentiminax\UX\DataTables\Attribute\AsDataTable;
use Pentiminax\UX\DataTables\Column\MoneyColumn;
use Pentiminax\UX\DataTables\Column\TextColumn;
use Pentiminax\UX\DataTables\Model\AbstractDataTable;
#[AsDataTable(Product::class)]
final class ProductsDataTable extends AbstractDataTable
{
public function configureColumns(): iterable
{
yield TextColumn::new('name', 'Product');
yield MoneyColumn::new('price', 'Price')->currency('EUR');
}
protected function mapRow(mixed $row): array
{
return [
'name' => $row->getName(),
'price' => $row->getPriceInCents(),
];
}
}
Related
- Number Column — plain integers and floats without currency formatting
- Columns Overview