Here is what I found out so far.
This is not complete but it can take you on the right path.
I conducted my tests by modifying the cms page listing ui component.
I added this
<item name="filter_url_params" xsi:type="array">
<item name="page_id" xsi:type="string">*</item>
</item>
in cms_page_listing.xml
inside the dataSource node inside the data/config argument. So now it looks like this
<dataSource name="cms_page_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Magento\Cms\Ui\Component\DataProvider</argument>
<argument name="name" xsi:type="string">cms_page_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">page_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="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">page_id</item>
</item>
<item name="filter_url_params" xsi:type="array"><!-- my addition -->
<item name="page_id" xsi:type="string">*</item>
</item>
</item>
</argument>
</argument>
</dataSource>
This allows me to call the url ROOT/admin/cms/page/index/key/<form_key_here>/?page_id=2
.
And I see only the page with id 2.
But it does not work for range filters and the filter value is not filled in. It still shows as blank.
Now here is why this is possible.
The dataProvider class for cms pages is Magento\Cms\Ui\Component\DataProvider
.
This one extends Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider
.
This last one contains a protected method called prepareUpdateUrl
protected function prepareUpdateUrl()
{
if (!isset($this->data['config']['filter_url_params'])) {
return;
}
foreach ($this->data['config']['filter_url_params'] as $paramName => $paramValue) {
if ('*' == $paramValue) {
$paramValue = $this->request->getParam($paramName);
}
if ($paramValue) {
$this->data['config']['update_url'] = sprintf(
'%s%s/%s',
$this->data['config']['update_url'],
$paramName,
$paramValue
);
$this->addFilter(
$this->filterBuilder->setField($paramName)->setValue($paramValue)->setConditionType('eq')->create()
);
}
}
}
What this does is to check in the ui component config if there is an element called filter_url_params
. If there is, it takes all the values inside it and checks the request for values matching what's defined in filter_url_params
.
But by default it works only with eq
.
What you can try is to have a custom dataSource for your component where you rewrite the method prepareUpdateUrl
and make it take into account all the request variables you need and maybe add paging to it and range filtering.
Side note: This is a very interesting question. I'm sure a lot of people will need this in the future.
I used Renderer to achieve this.
Please find my code here.
Layout File:
<block class="Magento\Backend\Block\Widget\Grid\Column" as="action">
<arguments>
<argument name="id" xsi:type="string">action</argument>
<argument name="header" xsi:type="string" translate="true">Action</argument>
<argument name="type" xsi:type="string">action</argument>
<argument name="getter" xsi:type="string">getId</argument>
<argument name="filter" xsi:type="boolean">false</argument>
<argument name="sortable" xsi:type="boolean">false</argument>
<argument name="index" xsi:type="string">entity_id</argument>
<argument name="is_system" xsi:type="boolean">true</argument>
<argument name="renderer" xsi:type="string">Apptha\Deal\Block\Adminhtml\Deal\Grid\Column\Renderer\Assignaction</argument>
<argument name="header_css_class" xsi:type="string">col-actions</argument>
<argument name="column_css_class" xsi:type="string">col-actions</argument>
</arguments>
</block>
Block file (Apptha\Deal\Block\Adminhtml\Deal\Grid\Column\Renderer\Assignaction.php):
<?php
namespace Apptha\Deal\Block\Adminhtml\Deal\Grid\Column\Renderer;
use \Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context;
use \Magento\Store\Model\StoreManagerInterface;
use \Apptha\Deal\Helper\Data;
class Assignaction extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Text
{
protected $_helper;
protected $urlBuilder;
public function __construct(\Magento\Framework\UrlInterface $urlBuilder)
{
$this->urlBuilder = $urlBuilder;
}
public function render(\Magento\Framework\DataObject $row)
{
/** @var \Magento\Integration\Model\Integration $row */
$merchantId = $row->getData("merchant_id");
$manageDealId = $row->getData("entity_id");
$actionUrl = $this->urlBuilder->getUrl("deals/deal/responsedetails/id/$manageDealId/mid/$merchantId" );
return "<a href=".$actionUrl.">Details</a>";
}
}
Best Answer
Please find below line in your ui component file.
After that add below code after that line.
You can get filter data in your grid.
Still you have any query let me know.