I have a button on a admin grid in Magento 2 which need to pass URL parameter coming on the grid page like:

enter image description here

I need to pass the dynamic param questionset_id (value = 19) to button 'Add New Question' in my admin grid (ui component):

<?xml version="1.0"?>
<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">alkemy_chatbot_questionsetflow_listing.alkemy_chatbot_questionsetflow_listing_data_source</item>
            <item name="deps" xsi:type="string">alkemy_chatbot_questionsetflow_listing.alkemy_chatbot_questionsetflow_listing_data_source</item>
        <item name="spinner" xsi:type="string">alkemy_chatbot_questionsetflow_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="back" xsi:type="array">
                <item name="name" xsi:type="string">back</item>
                <item name="label" xsi:type="string" translate="true">Back</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">alkemy_chatbot/questionset/index</item>
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">add</item>
                <item name="label" xsi:type="string" translate="true">Add New Question</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="url" path="alkemy_chatbot/questionsetflow/new">
                    <param name="questionset_id">!!!!!!!!</param>

What value is necessary to put in <param name="questionset_id">


  • Did you solved the above one?
    – Ramya
    May 26, 2020 at 16:09

1 Answer 1


Use button like here

And then add following line inside buttons tag

<button name="custom_button_name" class="Vendor\Module\Block\Adminhtml\CustomButton"/>


namespace Vendor\Module\Block\Adminhtml;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class CustomButton implements ButtonProviderInterface
     * Url Builder
     * @var \Magento\Framework\UrlInterface
    protected $urlBuilder;

     * CustomButton constructor.
     * @param \Magento\Backend\Block\Widget\Context $context
    public function __construct(
        \Magento\Backend\Block\Widget\Context $context
    ) {
        $this->urlBuilder = $context->getUrlBuilder();
     * @return array
    public function getButtonData()
        $data = [
            'label' => __('Custom Button'),
            'class' => 'save primary',
            'id' => 'custom-button',
            'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/url', ['id' => 2])),
            'sort_order' => 20,
        return $data;

     * Generate url by route and parameters
     * @param   string $route
     * @param   array $params
     * @return  string
    public function getUrl($route = '', $params = [])
        return $this->urlBuilder->getUrl($route, $params);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.