omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
262 stars 113 forks source link

Combine multiple collumns or use Entity methods #92

Closed timo002 closed 5 years ago

timo002 commented 5 years ago

I need to combine the result of multiple database column to one datatable columns. How can I get that working?

My Entity already has a method for it so I can call it in my controller or twig so I always get the same formating and only need to configure it once.

timo002 commented 5 years ago

Found my own anwser!

Entity/dummy.php

public function getSomething(): ?string
{
    return $this->someVar . '-' . $this->anotherVar;
}

In my datatables I need to add both columns $someVar and $anotherVar:

$dataTableFactory->create()
    ->add('someting', TextColumn::class, [
        'render' => function($value, $context) {
            return $context->getSomething();
        }
    ])
    ->add('someVar', TextColumn::class, ['visible' => false')
    ->add('anotherVar', TextColumn::class, ['visible' => false')