1

I have created the custom table to join sales_order_item and sales order grid. I need to display the order with complete status by default instead of pending status order.

I have searched for the same and got the solution for magento1, http://inchoo.net/magento/prepared-filter-for-magento-admin-grids/. Could anyone help me to implement the same filter by default on magento2

Now I am getting,

enter image description here

But I need to get complete status order details by default.

3

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

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.