I have created a custom module to display the sale product details. The columns are as follow, Product_id, name, quantity and Status. I got the output.
My question is, I need to display completed order details by default but now it's displaying the pending order details by default.
Could anyone give me suggestions to sort it out
2 Answers 2
Finally, I got the output,
In my xml that defines the grid, I replaced Magento\Backend\Block\Widget\Grid as Test\Custom\Block\Adminhtml\Custom
In my Grid.php
namespace Test\Custom\Block\Adminhtml\Custom;
use Magento\Backend\Block\Widget\Grid as WidgetGrid;
class Grid extends WidgetGrid
{
protected function _construct()
{
parent::_construct();
$this->setSaveParametersInSession(true);
//for default filter
if ($this->hasData('default_filter')){
$this->setDefaultFilter($this->getData('default_filter'));
}
}
protected function _prepareCollection()
{
//on clicking reset filter on Grid it will make 'complete' status as default:
if(!$this->getParam($this->getVarNameFilter(), null)) {
$this->getCollection()->addFieldToFilter('salesGrid.status', array('eq' => 'complete'));
$data['status'] = 'complete';
$this->_setFilterValues($data);
}
parent::_prepareCollection();
}
}
You need to modify your collections according to your requirement. Make collections filtered by order status complete.
-
Could you please find my updated question in magento.stackexchange.com/questions/135084/…Vigna S– Vigna S2016年09月07日 08:44:15 +00:00Commented Sep 7, 2016 at 8:44
-
I need to have default sorted filter on my collectionVigna S– Vigna S2016年09月07日 08:45:54 +00:00Commented Sep 7, 2016 at 8:45