Custom ProxyQuery not showing filters #108
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @davidromani! First of, judging by the provided screenshot, it seems like you're using a # config/packages/kreyu_data_table.yaml
kreyu_data_table:
defaults:
themes:
- '@KreyuDataTable/themes/bootstrap_5.html.twig' or in Twig: {% data_table_theme batchAnalysisTable '@KreyuDataTable/themes/bootstrap_5.html.twig' %}
{{ data_table(batchAnalysisTable) }} By the way, I don't think you need a custom proxy query, because you are still using Doctrine, therefore, you can use the built-in one. Unless you're using DBAL directly instead of ORM - I am not able to tell by provided code. You don't have to work on entities - anything returned by the Doctrine will work, even simple arrays. For example, if your QueryBuilder returns data in following format: [
[
'batchCode' => 2416,
'totalWorkstationSeconds' => 815.448,
],
[
'batchCode' => 2417,
'totalWorkstationSeconds' => 715.026,
]
] You can use the following column definition - note the property paths of each column is wrapped in square brackets, since its an array (re: reading from arrays in property access component): public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder
->addColumn('batchCode', TextColumnType::class, [
'label' => 'batchCode',
'property_path' => '[batchCode]',
])
->addColumn('totalWorkstationSeconds', NumberColumnType::class, [
'label' => 'totalWorkstationSeconds',
'property_path' => '[totalWorkstationSeconds]',
])
;
} You can even sort by those columns. By default, setting the public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder
->addColumn('batchCode', TextColumnType::class, [
'label' => 'batchCode',
'property_path' => '[batchCode]',
'sort' => 'batchCode',
])
->addColumn('totalWorkstationSeconds', NumberColumnType::class, [
'label' => 'totalWorkstationSeconds',
'property_path' => '[totalWorkstationSeconds]',
'sort' => 'totalWorkstationSeconds',
])
;
} Also, if you prefer to work on DTOs like in your example above, try returning them directly from QueryBuilder, by using the NEW DQL keyword. Working with built-in ProxyQuery will allow you to use the built-in filters, so make sure you are 100% sure you need custom adapter for your data. For example, as I mentioned before, if you're using Doctrine DBAL directly instead of an ORM - sure, there's no built-in adapter for that. |
Beta Was this translation helpful? Give feedback.
-
@Kreyu thanks for your hints and your time! I'll take a look and give you some feedback. |
Beta Was this translation helpful? Give feedback.
Hey @davidromani!
First of, judging by the provided screenshot, it seems like you're using a
base.html.twig
theme, which is incredibly minimal and not meant to be used directly - working as a base for other Bootstrap 5 and Tabler themes. Please try using one of those themes, described in the documentation:or in Twig:
By the way, I don't think you need a custom proxy query, because you are still using Doctrine, therefore, you can…