change di.xml and add replace <virtualType>
of datasource with <type>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="blackout_data_source" xsi:type="string">
vendor\module\Model\ResourceModel\BlackoutLimit\Grid\Collection
</item>
</argument>
</arguments>
</type>
Add <Type>
of grid/collection in same di.xml as below add variables name "maintable" "eventPrefix" "eventObject"
<type name="vendor\module\Model\ResourceModel\BlackoutLimit\Grid\Collection">
<arguments>
<argument name="mainTable" xsi:type="string">tm_blackout_days_limit</argument>
<argument name="eventPrefix" xsi:type="string">tm_blackoutlimit_blackout_collection</argument>
<argument name="eventObject" xsi:type="string">blackout_collection</argument>
<argument name="resourceModel" xsi:type="string">vendor\module\Model\ResourceModel\BlackoutLimit</argument>
</arguments>
</type>
Create Grid collection file as below
vendor\module\Model\ResourceModel\BlackoutLimit\Grid\Collection.php
<?php
namespace vendor\module\Model\ResourceModel\BlackoutLimit\Grid;
class Collection extends \vendor\module\Model\ResourceModel\BlackoutLimit\Collection implements
\Magento\Framework\Api\Search\SearchResultInterface
{
protected $_idFieldName = 'day_limit_id';
protected $_eventPrefix = 'tm_blackoutlimit_blackout_collection';
protected $_eventObject = 'blackout_collection';
/**
*
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param mixed|null $mainTable
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $eventPrefix
* @param mixed $eventObject
* @param mixed $resourceModel
* @param string $model
* @param null $connection
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
*/
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,
\Magento\Store\Model\StoreManagerInterface $storeManager, $mainTable, $eventPrefix, $eventObject, $resourceModel,
$model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document', $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null)
{
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
$this->logger = $logger;
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
$this->storeManager = $storeManager;
}
/**
*
* @return \Magento\Framework\Api\Search\AggregationInterface
*/
public function getAggregations()
{
return $this->aggregations;
}
/**
*
* @param \Magento\Framework\Api\Search\AggregationInterface $aggregations
* @return void
*/
public function setAggregations($aggregations)
{
$this->aggregations = $aggregations;
}
/**
*
* @return \Magento\Framework\Api\Search\SearchCriteriaInterface|null
*/
public function getSearchCriteria()
{
return $this->searchCriteria;
}
/**
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return $this @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$this->searchCriteria = $searchCriteria;
return $this;
}
/**
* Get total count.
*
* @return int
*/
public function getTotalCount()
{
return $this->getSize();
}
/**
* Set total count.
*
* @param int $totalCount
* @return $this @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setTotalCount($totalCount)
{
return $this;
}
/**
* Set items list.
*
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
* @return $this @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setItems(array $items = null)
{
return $this;
}
/**
* This is the function that will add the filter
*/
protected function _beforeLoad()
{
parent::_beforeLoad();
$mydate=getdate(date("U"));
$this->addFieldTOFilter( 'day_code',array( 'like' => '%'."$mydate[year]".'%' ) );
return $this;
}
}