How to add javascript event to action button from product grid in backendHow to add an action on a new button added on a backend form containerHow to get customer email from javascript?Add Javascript globally in Magento 2 backendMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formHow to call front controller from javascript?Magento2 How to Add placed order Product Quantity in Sales order grid in BackendForm is not displayed on panel admin Magento 2Magento2: How to remove ‘Add New’ button from Admin Grid?Magento 2 | Add Admin Configuration Button Action

Why does a variable size struct not compile in the Arduino IDE?

Would encrypting a database protect against a compromised admin account?

How to select certain lines (n, n+4, n+8, n+12...) from the file?

What does this quote in Small Gods refer to?

Why use steam instead of just hot air?

How to make a language evolve quickly?

Exception propagation: When to catch exceptions?

Two researchers want to work on the same extension to my paper. Who to help?

How to efficiently lower your karma

Why is the Sun made of light elements only?

Removing all characters except digits from clipboard

Has there been evidence of any other gods?

Why do the Avengers care about returning these items in Endgame?

Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?

Names of the Six Tastes

Company threw a surprise party for the CEO, 3 weeks later management says we have to pay for it, do I have to?

How did Thanos not realise this had happened at the end of Endgame?

Why are parallelograms defined as quadrilaterals? What term would encompass polygons with greater than two parallel pairs?

What was the notion of limit that Newton used?

What's the difference between const array and static const array in C/C++

Company stopped paying my salary. What are my options?

Extending Kan fibrations, without using minimal fibrations

Succinct and gender-neutral Russian word for "writer"

How to find the tex encoding of specific fonts?



How to add javascript event to action button from product grid in backend


How to add an action on a new button added on a backend form containerHow to get customer email from javascript?Add Javascript globally in Magento 2 backendMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formHow to call front controller from javascript?Magento2 How to Add placed order Product Quantity in Sales order grid in BackendForm is not displayed on panel admin Magento 2Magento2: How to remove ‘Add New’ button from Admin Grid?Magento 2 | Add Admin Configuration Button Action






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to open a new window on custom action link from product grid in admin panel.



I created vendor/magento/module-catalog/view/adminhtml/ui_component/product_listing.xml into custom module with code.



<actionsColumn name="actions" class="NamespaceModulenameUiComponentListingColumnsProductActions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
<item name="sortOrder" xsi:type="number">200</item>
</item>
</argument>
</actionsColumn>


In Namespace/Modulename/Ui/Component/Listing/Columns/ProductActions.php i have added custom action button Test.



public function prepareDataSource(array $dataSource)

if (isset($dataSource['data']['items']))
$storeId = $this->context->getFilterParam('store_id');

foreach ($dataSource['data']['items'] as &$item)
$item[$this->getData('name')]['edit'] = [
'href' => $this->urlBuilder->getUrl(
'catalog/product/edit',
['id' => $item['entity_id'], 'store' => $storeId]
),
'label' => __('Edit'),
'hidden' => false,
];
$item[$this->getData('name')]['test'] = [
'href' => 'javascript:void(0)',
'label' => __('Test'),
'hidden' => false,
];



return $dataSource;



Now i need to call JS function on click of this action button and then open a new window. I tried adding onclick and data-mage-init attribute there but it doesnot work.



Any solution?










share|improve this question




























    0















    I am trying to open a new window on custom action link from product grid in admin panel.



    I created vendor/magento/module-catalog/view/adminhtml/ui_component/product_listing.xml into custom module with code.



    <actionsColumn name="actions" class="NamespaceModulenameUiComponentListingColumnsProductActions">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="indexField" xsi:type="string">entity_id</item>
    <item name="sortOrder" xsi:type="number">200</item>
    </item>
    </argument>
    </actionsColumn>


    In Namespace/Modulename/Ui/Component/Listing/Columns/ProductActions.php i have added custom action button Test.



    public function prepareDataSource(array $dataSource)

    if (isset($dataSource['data']['items']))
    $storeId = $this->context->getFilterParam('store_id');

    foreach ($dataSource['data']['items'] as &$item)
    $item[$this->getData('name')]['edit'] = [
    'href' => $this->urlBuilder->getUrl(
    'catalog/product/edit',
    ['id' => $item['entity_id'], 'store' => $storeId]
    ),
    'label' => __('Edit'),
    'hidden' => false,
    ];
    $item[$this->getData('name')]['test'] = [
    'href' => 'javascript:void(0)',
    'label' => __('Test'),
    'hidden' => false,
    ];



    return $dataSource;



    Now i need to call JS function on click of this action button and then open a new window. I tried adding onclick and data-mage-init attribute there but it doesnot work.



    Any solution?










    share|improve this question
























      0












      0








      0








      I am trying to open a new window on custom action link from product grid in admin panel.



      I created vendor/magento/module-catalog/view/adminhtml/ui_component/product_listing.xml into custom module with code.



      <actionsColumn name="actions" class="NamespaceModulenameUiComponentListingColumnsProductActions">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="indexField" xsi:type="string">entity_id</item>
      <item name="sortOrder" xsi:type="number">200</item>
      </item>
      </argument>
      </actionsColumn>


      In Namespace/Modulename/Ui/Component/Listing/Columns/ProductActions.php i have added custom action button Test.



      public function prepareDataSource(array $dataSource)

      if (isset($dataSource['data']['items']))
      $storeId = $this->context->getFilterParam('store_id');

      foreach ($dataSource['data']['items'] as &$item)
      $item[$this->getData('name')]['edit'] = [
      'href' => $this->urlBuilder->getUrl(
      'catalog/product/edit',
      ['id' => $item['entity_id'], 'store' => $storeId]
      ),
      'label' => __('Edit'),
      'hidden' => false,
      ];
      $item[$this->getData('name')]['test'] = [
      'href' => 'javascript:void(0)',
      'label' => __('Test'),
      'hidden' => false,
      ];



      return $dataSource;



      Now i need to call JS function on click of this action button and then open a new window. I tried adding onclick and data-mage-init attribute there but it doesnot work.



      Any solution?










      share|improve this question














      I am trying to open a new window on custom action link from product grid in admin panel.



      I created vendor/magento/module-catalog/view/adminhtml/ui_component/product_listing.xml into custom module with code.



      <actionsColumn name="actions" class="NamespaceModulenameUiComponentListingColumnsProductActions">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="indexField" xsi:type="string">entity_id</item>
      <item name="sortOrder" xsi:type="number">200</item>
      </item>
      </argument>
      </actionsColumn>


      In Namespace/Modulename/Ui/Component/Listing/Columns/ProductActions.php i have added custom action button Test.



      public function prepareDataSource(array $dataSource)

      if (isset($dataSource['data']['items']))
      $storeId = $this->context->getFilterParam('store_id');

      foreach ($dataSource['data']['items'] as &$item)
      $item[$this->getData('name')]['edit'] = [
      'href' => $this->urlBuilder->getUrl(
      'catalog/product/edit',
      ['id' => $item['entity_id'], 'store' => $storeId]
      ),
      'label' => __('Edit'),
      'hidden' => false,
      ];
      $item[$this->getData('name')]['test'] = [
      'href' => 'javascript:void(0)',
      'label' => __('Test'),
      'hidden' => false,
      ];



      return $dataSource;



      Now i need to call JS function on click of this action button and then open a new window. I tried adding onclick and data-mage-init attribute there but it doesnot work.



      Any solution?







      magento2 magento-2.1






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 15 '17 at 6:26









      HungryDBHungryDB

      481832




      481832




















          1 Answer
          1






          active

          oldest

          votes


















          0














          I think you can extend Magento/Ui/view/base/web/templates/grid/cells/actions.html. Second solution, you can add a new column action for test like



          <actionsColumn name="test_actions" class="SpaceYourModuleUiComponentListingColumnTestAction">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
          <item name="indexField" xsi:type="string">id</item>
          <item name="sortable" xsi:type="boolean">false</item>
          <item name="label" xsi:type="string" translate="true">Test Action</item>
          <item name="urlEntityParamName" xsi:type="string">id</item>
          </item>
          </argument>
          </actionsColumn>


          And with class SpaceYourModuleUiComponentListingColumnTestAction in prepareDataSource, we have :



          $url = $this->urlBuilder->getUrl(
          'test_action',
          ['id' => $item['id']]
          );

          $html = '<a href="'. $url.'" target="_blank">
          <button class="action-scalable action-default scalable">Test</button></a>';
          $item[$this->getData('name')] = $html;





          share|improve this answer

























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159946%2fhow-to-add-javascript-event-to-action-button-from-product-grid-in-backend%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I think you can extend Magento/Ui/view/base/web/templates/grid/cells/actions.html. Second solution, you can add a new column action for test like



            <actionsColumn name="test_actions" class="SpaceYourModuleUiComponentListingColumnTestAction">
            <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
            <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
            <item name="indexField" xsi:type="string">id</item>
            <item name="sortable" xsi:type="boolean">false</item>
            <item name="label" xsi:type="string" translate="true">Test Action</item>
            <item name="urlEntityParamName" xsi:type="string">id</item>
            </item>
            </argument>
            </actionsColumn>


            And with class SpaceYourModuleUiComponentListingColumnTestAction in prepareDataSource, we have :



            $url = $this->urlBuilder->getUrl(
            'test_action',
            ['id' => $item['id']]
            );

            $html = '<a href="'. $url.'" target="_blank">
            <button class="action-scalable action-default scalable">Test</button></a>';
            $item[$this->getData('name')] = $html;





            share|improve this answer





























              0














              I think you can extend Magento/Ui/view/base/web/templates/grid/cells/actions.html. Second solution, you can add a new column action for test like



              <actionsColumn name="test_actions" class="SpaceYourModuleUiComponentListingColumnTestAction">
              <argument name="data" xsi:type="array">
              <item name="config" xsi:type="array">
              <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
              <item name="indexField" xsi:type="string">id</item>
              <item name="sortable" xsi:type="boolean">false</item>
              <item name="label" xsi:type="string" translate="true">Test Action</item>
              <item name="urlEntityParamName" xsi:type="string">id</item>
              </item>
              </argument>
              </actionsColumn>


              And with class SpaceYourModuleUiComponentListingColumnTestAction in prepareDataSource, we have :



              $url = $this->urlBuilder->getUrl(
              'test_action',
              ['id' => $item['id']]
              );

              $html = '<a href="'. $url.'" target="_blank">
              <button class="action-scalable action-default scalable">Test</button></a>';
              $item[$this->getData('name')] = $html;





              share|improve this answer



























                0












                0








                0







                I think you can extend Magento/Ui/view/base/web/templates/grid/cells/actions.html. Second solution, you can add a new column action for test like



                <actionsColumn name="test_actions" class="SpaceYourModuleUiComponentListingColumnTestAction">
                <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                <item name="indexField" xsi:type="string">id</item>
                <item name="sortable" xsi:type="boolean">false</item>
                <item name="label" xsi:type="string" translate="true">Test Action</item>
                <item name="urlEntityParamName" xsi:type="string">id</item>
                </item>
                </argument>
                </actionsColumn>


                And with class SpaceYourModuleUiComponentListingColumnTestAction in prepareDataSource, we have :



                $url = $this->urlBuilder->getUrl(
                'test_action',
                ['id' => $item['id']]
                );

                $html = '<a href="'. $url.'" target="_blank">
                <button class="action-scalable action-default scalable">Test</button></a>';
                $item[$this->getData('name')] = $html;





                share|improve this answer















                I think you can extend Magento/Ui/view/base/web/templates/grid/cells/actions.html. Second solution, you can add a new column action for test like



                <actionsColumn name="test_actions" class="SpaceYourModuleUiComponentListingColumnTestAction">
                <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                <item name="indexField" xsi:type="string">id</item>
                <item name="sortable" xsi:type="boolean">false</item>
                <item name="label" xsi:type="string" translate="true">Test Action</item>
                <item name="urlEntityParamName" xsi:type="string">id</item>
                </item>
                </argument>
                </actionsColumn>


                And with class SpaceYourModuleUiComponentListingColumnTestAction in prepareDataSource, we have :



                $url = $this->urlBuilder->getUrl(
                'test_action',
                ['id' => $item['id']]
                );

                $html = '<a href="'. $url.'" target="_blank">
                <button class="action-scalable action-default scalable">Test</button></a>';
                $item[$this->getData('name')] = $html;






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jul 13 '17 at 7:09

























                answered Jul 12 '17 at 17:53









                jennyjenny

                13




                13



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159946%2fhow-to-add-javascript-event-to-action-button-from-product-grid-in-backend%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?