Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback Filter #2513

Closed
Warxcell opened this issue Oct 22, 2014 · 9 comments
Closed

Callback Filter #2513

Warxcell opened this issue Oct 22, 2014 · 9 comments

Comments

@Warxcell
Copy link
Contributor

Hello, when you have CallbackFilter, when page is refreshed the filter is hidden and you have to show it again.

Btw: I really like that filters are above table. It's very convenient. :)

@Warxcell Warxcell changed the title Filter checkbox Callback Filter Oct 22, 2014
@webdevilopers
Copy link
Contributor

👍

@julbrs
Copy link

julbrs commented Dec 29, 2014

Hum same need here, 👍 :)

Thanks for this new design I am also big fan of it :)

@pulzarraider pulzarraider added this to the 2.4 milestone Dec 30, 2014
@pulzarraider
Copy link
Contributor

@Warxcell @webdevilopers @bobman38 can you please provide an example?

@julbrs
Copy link

julbrs commented Jan 4, 2015

Hi, here is a part of my CompanyAdmin :

// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $partnerCompanyOptions = array(
        'class' => 'Gbs\SupportBundle\Entity\Company',
        'required' => false,
        'query_builder' => function($repository) {
            return $repository->getPartners();
        },
    );

    $salesRepOptions= array(
        'class' => 'Gbs\SupportBundle\Entity\User',
        'required' => false,
        'query_builder' => function($repository) {
            return $repository->findSalesQB();
        },
    );

    $datagridMapper
        ->add('name')
        ->add('client', 'doctrine_orm_string', array(), 'choice', array('choices' => Company::$CLIENT))
        ->add('isPartner')
        ->add('partnerCompany', null, array(), null, $partnerCompanyOptions)
        ->add('salesRep', null, array(), null, $salesRepOptions)
        ->add('sector')
        ->add('canInvoice')
        ->add('address')
        ->add('country')
    ;

    $datagridMapper->add('geoLat', 'doctrine_orm_callback', array(
        'label' => 'GeoData',
        'callback' => function($queryBuilder, $alias, $field, $value) {
            if ($value['value'] == 1) {
                $queryBuilder->andWhere($alias . '.geoLat IS NOT NULL');
            }
            else if ($value['value'] == 2) {
                $queryBuilder->andWhere($alias . '.geoLat IS NULL');
            }
        }
        ), 'choice', array(
            'choices' => array('All', 'Provided', 'Not Provided')
        )
    );
}

With the callback definition, this is doing the issue. Let me know if you need more info,
THANKS !

@Warxcell
Copy link
Contributor Author

Warxcell commented Jan 4, 2015

In code there is check if callback function returns true then it's shown, otherwise not.

@pulzarraider
Copy link
Contributor

Yes, the return value is checked. So the callback function should return true if it's applied (if does not contain empty value).

@bobman38 can you add return true; to your callback filter and test if everything works properly?

@julbrs
Copy link

julbrs commented Jan 4, 2015

OK it works I understand... So in my case the function must return true if value is equal to 1 or 2. And then the filter is correctly shown after the page refresh.

Sorry for the noise and thanks for the tip.

@pulzarraider
Copy link
Contributor

@bobman38 thank you for feedback.

If everything is clear now, can we close this issue @Warxcell?

@webdevilopers
Copy link
Contributor

Everything looks fine. Should be closed @Warxcell !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants