Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8818041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:00:01+00:00 2026-06-14T05:00:01+00:00

the following piece of code is working, except for one thing. The filter used

  • 0

the following piece of code is working, except for one thing. The filter used for the departments should be dependent on the value selected in the filter for a region (a department belongs to one region). I’ve tried with the FindAllByAttributes() there that you see on the department filter, but it isn’t working. I can use FindAll() but then the two filters are not related. Any ideas on how to achieve this ?

thanks

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'mainGrid',
'dataProvider'=>$model->filterForDefaultSalesUserManagement(),
'filter'=>$model,
'columns'=>array(
                    array(
                            'class'=>'CCheckBoxColumn',
                            'id'=>'checkedColumn',
                            'selectableRows'=>2
                         ),
                    array(
                            'name'=>'Fr_RegionId',
                            'header'=>'Region',
                            'value'=>'$data->frDepartment->frRegion->NameFR',
                            'filter'=>CHtml::listData(FrRegion::model()->findAll(),'Id','NameFR')
                         ),
                    array(
                            'name'=>'Fr_DepartmentId',
                            'header'=>'Department',
                            'value'=>'$data->frDepartment->NameFR',
                            'filter'=>CHtml::listData(FrDepartment::model()->findAllByAttributes(
                                    array(),
                                    $condition = "fr_RegionId = :regionId",
                                    $params = array(':regionId'=>$data->frDepartment->frRegion->Id)
                                    ),
                                    'Id','NameFR')
                         ),
                    'PostalCode',
                    'NameFR',
                    )
));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:00:02+00:00Added an answer on June 14, 2026 at 5:00 am

    Change your params for the Department filtering to the following:

    array(':regionId'=>$model->Fr_RegionId)
    

    Assuming the filtering by Region already works, then this should work as well.

    Your currently posted code does not work because you are trying to access the $data object, which does not exist in the scope you are using it in. It is only used on a per-row basis, and refers to the objects returned via the dataProvider.

    You need to filter using $model‘s attributes. Since you are using the Fr_RegionId attribute of whatever object $model is for the Region column, then you can also use it to further filter your Department column.

    Note: You may have to adjust whether to even filter the Department at all, as if nothing is set in the FR_RegionId attribute, then it will attempt to match where the Department is blank. Or it will throw an error, depending on how you have your database set up.

    'filter'=>$model->Fr_RegionId?
        CHtml::listData(FrDepartment::model()->findAllByAttributes(
           array(),
           "fr_RegionId = :regionId",
           array(':regionId'=>$model->Fr_RegionId)),
           'Id','NameFR'):
        false,
    

    Try the above. It should let you filter Department if Fr_RegionId is selected from the Region dropdown box, and otherwise it won’t let you filter at all.

    Or, if you want to let every Department be available if no Region is selected, then replace false with

    CHtml::listData(FrDepartment::model()->findAll(),'Id','NameFR')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why isn't the following piece of code working in IE8? <select> <option onclick=javascript: alert('test');>5</option>
The following piece of code is working on Android devices and iPhone simulator but
The following piece of code is used to print the time in the logs:
The following piece of code should read each line of the file and operate
I have the following piece of code its working fine,no issues but i am
I have the following piece of code which is not working the way I
While working with annotations I stumbled accross the following piece of code (it's the
I can't find a working solution for the following piece of code: def search_last_rate
I wrote following piece of code to retrieve value of 'recipientList' in array abc
I used the following piece of code in the web.config in order to maintain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.