I created a filter for the backend of my component like this:

<field  name        =       "category_id"
        type        =       "category"
        label       =       "JOPTION_FILTER_CATEGORY"
        extension   =       "com_bestia.items"
        description =       "JOPTION_FILTER_CATEGORY_DESC"
        onchange    =       "this.form.submit();" >
            <option value   =   "">JOPTION_SELECT_CATEGORY</option>

I added the filter to my view by adding this to my view.html.php

    $this->filterForm   =   $this->get('FilterForm');
    $this->activeFilters=   $this->get('ActiveFilters');

and this to my layout:

    echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this));

Well, this works great, but if I change the state of the item by clicking on the little button next to each entry, which is defined like this:

    <td class="small">
        <?php echo JHtml::_('jgrid.published', $item->state, $i, 'items.', $canChange, 'cb'); ?>

the filter is not working anymore. It is still checked but the view shows results of all components.

Any ideas how to fix that?

Edit: This is the contractor of the model:

public function __construct($config = array()) 
    if (empty($config['filter_fields'])) {
        $config['filter_fields']    =   array(
                                                'id', 'a.id',
                                                'title', 'a.title', 
                                                'catid', 'nc.catid', 'category_title',                                          
                                                'state', 'a.state',
                                                'created_by', 'a.created_by'


This is the populateState-method of the model:

 * populateState function.
 * @access protected
 * @param mixed $ordering (default: null)
 * @param mixed $direction (default: null)
 * @return void
protected function populateState($ordering = null, $direction = null) 
    // Initialise variables.
    $app        =   JFactory::getApplication('administrator');

    // Load the filter state.
    $search     =   $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
    $this->setState('filter.search', $search);

    $published  =   $app->getUserStateFromRequest($this->context . '.filter.state', 'filter_published', '', 'string');
    $this->setState('filter.state', $published);

    $categoryId = $this->getUserStateFromRequest($this->context . '.filter.catid', 'filter_category_id', '');
    $this->setState('filter.catid', $categoryId);                        

    // Load the parameters.
    $params     =   JComponentHelper::getParams('com_bestia');
    $this->setState('params', $params);

    // List state information.
    parent::populateState('a.id', 'asc');

Another interesting fact: In the getListQuery I'm getting the catid by using

    // Filter by category.
    $categoryId     =       $this->getState('filter.catid');    

this has a value if I filter by category - but is has no value if I click on one of the publishing-buttons you can see on the screenshot:

enter image description here

3 Answers 3


Okay, my try ; )

check if your category filter presists after clicking pagination link. I give 99% for not storing your filter into state value. You need to store this filter in $this->state after sending form. Then check if this filter is set when you creating a query in getListQuery method in your model.

  • Hi Lahna... Well, the pagination-link is not tested yet. My problem is about the grid-button (publish, unpublish) in the list itself. If I click it the category-filter is still set but there are objects in the list that do not belong to the chosen category. If I do not click this button the filter works fine and only entries from the chosen category are shown.
    – MyFault
    May 1, 2016 at 19:17
  • Added populateState() and construct-method of the model to my initial question. Hope this helps :-)
    – MyFault
    May 1, 2016 at 19:22

Your filter xml looks right

Did you add the filter field to your model __construct()?

public function __construct($config = array())
    if (empty($config['filter_fields']))
        $config['filter_fields'] = array(...
                     'catid', 'a.catid', 'category_id', 'category_title',);

protected function populateState($ordering = null, $direction = null)
$this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'string'));

Is your model's populateState() getting the user state and setting the filter?

Right now it sounds like your view is aware of the field, but your model doesn't know what to do with it.

  • 1
    Hi Walt. I added my populateState() and constructor to the initial question. I think they are correct...
    – MyFault
    May 1, 2016 at 19:21
  • I have made some corrections in my answer, that should help you... based on github.com/joomla/joomla-cms/blob/… May 2, 2016 at 2:48
  • Hi Walt and thanks a lot for your work... Unfortunately it still does not work. Always when I click the button the filters are marked as active but they are not effective. Should I show you the custom code of the button itself? It's a HTML-helper that extends JHtmlItems.
    – MyFault
    May 2, 2016 at 6:57
  • Give US your filter xml
    – Lanah
    May 2, 2016 at 11:18
  • Hi, I uploaded it to d.pr/Z7DQ .
    – MyFault
    May 26, 2016 at 7:02

I assume you are extending JModelList? I bet your filters after getting overridden by the parent::populateState('a.id', 'asc');.

Have you tried called the parent::populateState('a.id', 'asc'); at the beginning of your populateState method instead of at the end?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.