How to assign HTTP request (GET or POST) value to the filter for the custom component list view
I have create the custom component which maintain product details and stock details, whenever the stock become low it'll send email to admin, in that i have pass the value for product and product category value in URL link using query string. when the admin click link from the email,it will go to the stock page and show the product details from the list of product.
The problem i was facing is, it not showing result for url query string value when click the mail link, it only showing previous session state value.
Note: Otherwise filter working well in back-end and front-end,and showing the result properly.
am using below code in edit.php.
$jInput = JFactory::getApplication()->input;
// From GET
$qid = $jInput->get->get( 'qid', 0, 'INT' );
$qcatid = $jInput->get->get( 'qcatid', 0, 'INT' );
if(!empty($qid)){
//$proname="id:".$qid;
$proname =$model->getArticleDetails('name',$qid);
$this->state->set('filter.search',$proname);
if(!empty($qcatid))
$this->state->set('filter.productcat',$qcatid); ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
document.id('filter_search').value='<?php echo $proname; ?>';
document.id('productcatselect').value='<?php echo $qcatid; ?>';
document.forms["adminForm"].submit();
}
</script>
<?php } ?>
In the model file constructor
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'product', 'a.fk_product_code',
'productcat', 'a.fk_productcat',
);
}
parent::__construct($config);
}
in populateState function
//Filtering productname
$search =trim($this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.search', $search);
//Filtering productcat
$this->setState('filter.productcat', $app->getUserStateFromRequest($this->context.'.filter.productcat', 'filter_productcat', ''));
Note: Product name using textbox filter, Product category using selectListbox filter.
Query string url is
'<a target="_blank" href="index.php?option=com_mycomponent&view=my_view&qid=product_id&qcatid=product_id">link</a>'
Found the solution, Instead of above link. Pass the email link like below
<a target="_blank" href="index.php?option=com_mycomponent&view=my_view&filter_search=product_name&filter_productcat=product_id">link</a>
Note: filter_search,filter_productcat are filter name, Refer from populateState function