9

We are implementing the core search tools in our custom component list view. When I click the search tools it shows the below form which is perfect.

enter image description here

When I click the drop down and select a particular status Ex.'Trashed' the page gets submitted and the form loaded with only the trashed records which is also perfect.

After the page load completed the search tools is not showing the filters by default. The user again need to click on search tools button to open the filters to reset the selected status.

How can I make the search tools to show the filters by default?

3 Answers 3

8

I managed to add options as below

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

If $hidden is set as 0 then the search tools will not be hidden. I set this variable appropriately based on the selected filter values.

3

The filter fields will automatically populated if they are listed in your Model's $config['filter_fields'] array in the constructor.

For example:

public function __construct ($config = array())
{
    if (empty($config['filter_fields']))
    {
        $config['filter_fields'] = array(
                'id', 'a.id',
                'title', 'a.title',
                'alias', 'a.alias',
                'checked_out', 'a.checked_out',
                'checked_out_time', 'a.checked_out_time',
                'catid', 'a.catid',
                'category_title',
                'published', 'a.published',
                'access', 'a.access',
                'access_level',
                'created', 'a.created',
                'created_by', 'a.created_by',
                'ordering', 'a.ordering',
                'featured', 'a.featured',
                'language', 'a.language',
                'hits', 'a.hits',
                'publish_up', 'a.publish_up',
                'publish_down', 'a.publish_down'
        );
    }

    parent::__construct($config);
}
1
  • Thanks. But its not working. I have those fields configured in the config variable in the constructor but still I need to click the 'Search Tools' button to open the filter options. When I do some more research on the view source I found the "filtersHidden":true is always set as true in my case. May 11, 2015 at 21:35
2

I ran into the same issue but have tracked it down to what it is. It is a multi-step process to setup the filters.

  1. For the filters to work you need to add filter_.xml file in the models/forms folder. This takes a regular Joomla XML file.
  2. You need to have the filters set as mentioned by @Nagarjun in your model
  3. In your view you need to add this line into the display function

    $this->activeFilters = $this->get('ActiveFilters');
    
  4. In case you have docblocks you need to specify it as a public variable:

    /**
      * List of active filters
      *
      * @var    array
      * @since  1.0
      */
    public $activeFilters = array();
    
  5. Finally add the filters to your template file:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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