Reference: How to add the store view to my module admin grid
for store grind column use below code. store is database coulmn name
$this->addColumn('store', array(
'header' => 'Website',
'index' => 'store',
'type' => 'store',
'width' => '100px',
'store_view'=> true,
'display_deleted' => false,
'renderer' => 'Namespace_Modulename_Block_Adminhtml_Store',
));
for rendering the stores
<?php
class Namespcae_Modulename_Block_Adminhtml_Store
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{ $store=explode(',',$row->getStore());
$data="";
if($row->getStore()!="" and $row->getStore()==0)
{
$allstore=Mage::app()->getStores();
foreach($allstore as $astore)
{
$data.=$astore->getName().'<br />';
}
} else {
$data="";
$a=0;
foreach ($store as $sto)
{
$data= $data.Mage::getModel('core/store')->load($sto[$a])->getName().'<br>';
$a+1;}
}
return $data;
}
}
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.
Best Answer
Create a column similar to this in your ui component for the grid page or update the already existing one with options and config nodes just as below.