Closed 99hops closed 5 years ago
Looking at https://github.com/omines/datatables-bundle/blob/master/src/Adapter/Doctrine/ORMAdapter.php#L209-L211 it seems indeed I misdocumented that feature and you are now using it correctly, although you can still shorthand it a ton by using similar syntax to my example.
I'm not really sure why I would've made such a mistake, I'm pretty sure I constructed the samples from actual working code, but it also seems to work the same in the v0.1 branch.
Ah found the culprit at https://github.com/omines/datatables-bundle/commit/6250255950952e6059dc582d92bd061caf2699db#diff-186d04d89cd58b4ab485e7ca6200e576L159
I apparently refactored that right before I tagged 0.1.0 hehe. PR welcome if you like :)
Is it my mistake or there is something wrong with the sample in the doc? How to make cryteria work? Is there any other solution to make condition to sql query?
$table = $this->createDataTable()
->add('nazwaBiegu', TextColumn::class, ['label' => 'Nazwa biegu', 'className' => 'bold'])
->add('dyscyplina', TextColumn::class,['label' => 'dyscyplina','field' => 'u.dyscyplina',"searchable" => true] )
->add('nazwaBieguSkrot', TextColumn::class)
->createAdapter(ORMAdapter::class, [
'entity' => Biegi::class,
'query' => function (QueryBuilder $qb) {
$qb
->select('u')
->from(Biegi::class, 'u')
;
},
'criteria' => [
function () {
return Criteria::create()->andWhere(new Comparison('u.dyscyplina', Comparison::EQ, 'nordic'));
},
new SearchCriteriaProvider()
],
])
->handleRequest($request);
Why do you reply to this issue if you're not going to read the previous replies?
Hi How to parsing external variable in criteria side?
$patient = $patientRepo->findOneBy(['userId' => $code_patient]);`
$table = $this->createDataTable()
->add('saveAt', DateTimeColumn::class, ['label' => 'Save At', 'format' => 'd-m-Y'])
->add('age', TextColumn::class, ['label' => 'Age (ans)'])
->add('telephone', TextColumn::class, ['label' => 'Telephone'])
->add('seenAt', DateTimeColumn::class, ['label' => 'Seen the', 'format' => 'd-m-Y'])
->add('closedAt', DateTimeColumn::class, ['label' => 'Closed At', 'format' => 'd-m-Y'])
->add('consult', TextColumn::class, ['label' => 'Consult', 'field' => 'consult.code'])
->createAdapter(ORMAdapter::class, array(
'entity' => Parameter::class,
'query' => function(QueryBuilder $builder) {
$builder
->select('p')
->from(Parameter::class, 'p')
->leftJoin('p.idConsult', 'consult')
->leftJoin('p.idPatient', 'patient')
->addSelect('consult')
->addSelect('patient');
},
'criteria' => function(QueryBuilder $builder) {
$builder->andWhere($builder->expr()->eq('patient.id', ':id'))->setParameter('id', $patient.getId());
}
))
->add('status', TextColumn::class, ['label' => 'Status'])
->add('id', TextColumn::class, ['label' => '', 'render' => function($value, $context) {
return sprintf('<a href="%s" class="btn btn-xs btn-primary"><i class="fa fa-eye"></i></a>',
$this->generateUrl('parameter_show', ['id' => $value, 'idPatient' => $patient->getId()])
);
}])
->handleRequest($request)
;`
when i run my code above i have variable not recognized as error
when I run my code above I have variable patient not recognized as error.
It could be just me doing something wrong but taking the "Customizing criteria" code snippet from the documentation doesn't produce anything in the end SQL query (has no effect and throws no error no matter what you type as criteria), I've tried with simple closure and as documented with no effect:
What works for me is:
But that's not the same, also "Note that implementing your own criteria overrides the default, meaning searching and sorting will no longer work automatically." doesn't seem to be true as well (at least in the above configuration) since sorting is still working with the added criteria.
omines/datatables-bundle ^0.2.1 / Symfony 4.2.2 / PHP 7.2.14
Is there something I am missing here :smiley: