Sure,
There are four things/places you need to do/edit,
1. Pages- view.html.php
Refer joomla's default component com_weblinks for reference.
There in the sidebar you need to add a custom filter.
***************************************************
JHtmlSidebar::setAction('index.php?option=com_book&view=pages');
JHtmlSidebar::addFilter(
//get list of countries options
from the model
$country_options = $this->get('CountriesOptions');
JHtmlSidebar::addFilter(
JText::_('SELECT_COUNTRY'),
'filter_country_options',
JHtml::_('select.options', $country_options, 'value', 'text', $this->state->get('filter.country_options'), true)
);
***************************************************
In the pages model,2. getCountriesOptions() where you told you already done a select query and did that
********************************************************
public function getCountriesOptions(){
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('a.country_id,a.country_name');
$query->from('#__ppinvoice_countries AS a');
$query->where('state = 1');
$query->order('a.country_name');
$db->setQuery($query);
$countries = $db->loadObjectList();
$country_options = array();
foreach($countries as $item) {
$country_options[] = JHTML::_('select.option', $item->country_id, $item->country_name);
}
return $country_options;
}
********************************************************
3. function populateState(){}
you need to add two lines
***************************************************
$type = $app->getUserStateFromRequest($this->context.'.filter.country_type', 'filter_country_type', '', 'string');
$this->setState('filter.country_type', $type);
***************************************************
4. And the last one, in the same model file in getListQuery function you need to add another where clause or where query to that, which will filter the result.
***************************************************
// Filter by Country.
$country = $this->getState('filter.country_options');
if ($country) {
$query->where('a.country_id = '.$db->quote($country));
}
***************************************************
I hope this helps.
Best regards
Sasi varna kumar
Lead developer - J2Store