You can add a column at the end of the grid of type Action
.
Something like this:
Inside the tag <columns>
add this at the end
<actionsColumn name="actions" class="[Namespace]\[Module]\Ui\Component\Listing\Column\[Endity]Actions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="indexField" xsi:type="string">[pk_id]</item>
<item name="urlEntityParamName" xsi:type="string">[param_used_in_get]</item>
</item>
</argument>
</actionsColumn>
then create the class [Namespace]\[Module]\Ui\Component\Listing\Column\[Entity]Actions
.
namespace [Namespace]\[Module]\Ui\Component\Listing\Column;
class [Entity]Actions extends \Magento\Ui\Component\Listing\Columns\Column
{
const URL_PATH_EDIT = '[module]/[entity]/edit';
/**
* URL builder
*
* @var \Magento\Framework\UrlInterface
*/
protected $_urlBuilder;
/**
* constructor
*
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
* @param \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory
* @param array $components
* @param array $data
*/
public function __construct(
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\View\Element\UiComponent\ContextInterface $context,
\Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory,
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) {
if (isset($item['mage_prod'])) {
$item[$this->getData('name')] = [
'edit' => [
'href' => $this->_urlBuilder->getUrl(
static::URL_PATH_EDIT,
[
'[get_var]' => $item['[pk]_id']
]
),
'label' => __('Edit')
],
];
}
}
}
return $dataSource;
}
}
getGridUrl
would determine the url where you are redirected when clicking on the row. The new ui component approach, when clicking a row, you either enter in the inline edit mode or nothing happens.mage_prod
attribute, people should be able to access the product edit page by clicking the row.actions
column with an edit link at the end of the grid. Would that fit your needs?