0

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

1

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();
        }
    }
0

You need to modify your collections according to your requirement. Make collections filtered by order status complete.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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