How we can display sales_order grid in custom module with only pending status.
For now I display sales_order_grid using ui component. I only want to display pending orders in this grid
Using This link you can create Admin grid. Click here Or You can Download Module and modify it.
You can change You table name and primary key from below file.
Emipro/Custom/Model/ResourceModel
Job.php
<?php
namespace Emipro\Custom\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class Job extends AbstractDb
{
protected function _construct()
{
$this->_init('Table_Name', 'Primary_Key_Name');
}
}
After In emipro_custom_job_listing.xml file at Emipro/Custom/view/adminhtml/ui_component you need to change column name also.
Now your Grid is ready now you need only modify one file which is give below:
Update Collection.php at Emipro/Custom/Model/ResourceModel/Job/Grid
<?php
namespace Emipro\Custom\Model\ResourceModel\Job\Grid;
use Emipro\Custom\Model\ResourceModel\Job\Collection as JobCollection;
use Magento\Framework\View\Element\UiComponent\DataProvider\Document as JobModel;
class Collection extends JobCollection implements \Magento\Framework\Api\Search\SearchResultInterface
{
protected $aggregations;
// @codingStandardsIgnoreStart
public function __construct(
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
\Magento\Framework\Event\ManagerInterface $eventManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = JobModel::class,
$connection = null,
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
) {
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
}
// @codingStandardsIgnoreEnd
public function getAggregations()
{
return $this->aggregations;
}
public function setAggregations($aggregations)
{
$this->aggregations = $aggregations;
}
public function getAllIds($limit = null, $offset = null)
{
return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
}
public function getSearchCriteria()
{
return null;
}
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
{
return $this;
}
public function getTotalCount()
{
return $this->getSize();
}
public function setTotalCount($totalCount)
{
return $this;
}
public function setItems(array $items = null)
{
return $this;
}
public function _beforeLoad()
{
parent::_beforeLoad();
$this->addFieldToFilter("status", "pending");
return $this;
}
}
I Hope This Helps You.
Add filter in ui component dataSource tag uicomponent.xml
<dataSource name="vtn_unexportedorder_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
<argument name="name" xsi:type="string">vtn_unexportedorder_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="filter_url_params" xsi:type="array">
<item name="status" xsi:type="string">pending</item>
</item>
</item>
</argument>
</argument>
</dataSource>
In above code added filter_url_params and apply filter where status equals to pending
<item name="filter_url_params" xsi:type="array">
<item name="status" xsi:type="string">pending</item>
</item>