<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">Meetansi_Extension_post_listing.Meetansi_Extension_post_listing_data_source</item>
<item name="deps" xsi:type="string">Meetansi_Extension_post_listing.Meetansi_Extension_post_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">spinner_columns</item>
<item name="buttons" xsi:type="array">
<item name="add" xsi:type="array">
<item name="name" xsi:type="string">add</item>
<item name="label" xsi:type="string" translate="true">Add New Post</item>
<item name="class" xsi:type="string">primary</item>
<item name="url" xsi:type="string">*/*/new</item> <- need controller?
</item>
</item>
</argument>
<dataSource name="nameOfDataSource">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class"
xsi:type="string">MagentoFrameworkViewElement
UiComponentDataProviderDataProvider</argument>
<argument name="name"
xsi:type="string">Meetansi_Extension_post_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="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
</item>
</argument>
</argument>
</dataSource>
ControllerAdminhtmlPostIndex.php
<?php
namespace MeetanshiExtensionControllerAdminhtmlPost;
class Index extends MagentoBackendAppAction
{
protected $resultPageFactory = false;
public function __construct(
MagentoBackendAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory
)
{
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend((__('Posts')));
return $resultPage;
}
}
UiComponentlistingColumnAction.php
<?php
namespace MeetanshiExtensionUiComponentListingColumn;
use MagentoFrameworkUrlInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
class Actions extends Column
{
protected $urlBuilder;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
) {
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
*
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$actions = $this->getData('action_list');
foreach ($actions as $key => $action) {
$params = $action['params'];
foreach ($params as $field => $param) {
$params[$field] = $item[$param];
}
$item[$this->getData('name')][$key] = [
'href' => $this->urlBuilder->getUrl(
$action['path'],
['id' => $item[$action['params']['id']]]
),
'label' => $action['label'],
'hidden' => false,
];
}
}
}
return $dataSource;
}
}