1

I have created Custom component from component-creator website now I want to add Search tools to this component, Search component like Article search provides. can anyone guide me from where I can add this functionality.

What I have done is add a custom filter code to view.html.php as shown below:

$db = JFactory::getDbo();

$query = "SELECT DISTINCT countryname as x FROM sugee_sugee_country where state=1 ORDER BY id ASC";
$db->setQuery($query); 
$rows = $db->loadObjectList(); 
$options = array();
$this->state->get('filter.countryname');
foreach ($rows as $row) {
      $options[] = JHtml::_('select.option', "$row->x", JText::_($row->x));
}

JHtmlSidebar::addFilter(
    '- Select Country -',
    'countryname',
    JHtml::_('select.options',$options,'value', 'text', $this->state->get('filter.countryname'), false));

My problem is that it does not work properly it always refresh the page and it does save its state like if i select INDIA then it should save INDIA as default. but it is not working and records are also not showing properly.

I have to create any other files for this or i have add any code or function anywhere else ?

Please guide.

2

I think you are part way there. Have a look in your components model for the getListQuery() function. That is where the filter will be applied to the list before it is sent back to the view.

In the same file is a populateState() function where you can get filter.countryname from the request and set it before the page is displayed.

Have a look at how this is done in com_content/models/articles.php for guidance on how to apply it to your code.

  • Thanks john, I have done the same and got the solution for this. – Info Truth Jan 25 '17 at 9:08
1

This probably is late reply but it might help others who are looking to add search tools on list view in Joomla backend.

Using 'Search Tools' on Joomla 3.x at admin backend for list views

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.