mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-04 15:34:35 +02:00
Improved formatting of the mass Part Lists column
This commit is contained in:
parent
b3956c7c4d
commit
1915acf069
2 changed files with 38 additions and 1 deletions
35
src/DataTables/Column/SIUnitNumberColumn.php
Normal file
35
src/DataTables/Column/SIUnitNumberColumn.php
Normal 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']);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue