omines / datatables-bundle

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

Ordering datatable for values which will be calculated #91

Closed mschrading closed 5 years ago

mschrading commented 5 years ago

Hi all. I have a datatable with value from a db table. Ordering this is easy but now I have a data column in the omines datatable with a value that comes from a method and not from a table column. On load it will be shown correctly but I what to order this column. But it didn't work

->add('admin',
                TextColumn::class,
                [
                    'label' => 'User is Admin',
                    'searchable' => false,
                    'orderable' => true,
                    'className' => 'table-actions',
                    'field' => 'user.id',
                    'render' => function ($id, $user) {
                        if ($user->isAdmin() == true) {
                            return '<i class="fas fa-check pl-2"></i>';
                        } else {
                            return '<i class="fas fa-times pl-2"></i>';
                        }
                    }
                ]
            )

It does not sort for admin boolean but for the user.id... but how to config this so it will be sorted for admins! Is there an example how to handle this kind of problem?

Thanks a lot Michael

curry684 commented 5 years ago

In the default Doctrine adapter the sorting is done on the query level, so you cannot interfere based on rendering of course, it would break filtering and pagination. Consider using a custom adapter instead.