Improved formatting of the mass Part Lists column

This commit is contained in:
Jan Böhmer 2022-09-10 00:37:47 +02:00
parent b3956c7c4d
commit 1915acf069
2 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1,35 @@
<?php
namespace App\DataTables\Column;
use App\Services\SIFormatter;
use Omines\DataTablesBundle\Column\AbstractColumn;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SIUnitNumberColumn extends AbstractColumn
{
protected $formatter;
public function __construct(SIFormatter $formatter)
{
$this->formatter = $formatter;
}
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefault('precision', 2);
$resolver->setDefault('unit', '');
}
public function normalize($value)
{
//Ignore null values
if ($value === null) {
return '';
}
return $this->formatter->format((float) $value, $this->options['unit'], $this->options['precision']);
}
}