1

How we can add "new column" and "new action" in newsletter in magento2 admin grid as Newsleter doesn't have ui_component .

So anybody can please help me as i can see newsletter grid is coming from newsletter_subscriber_block.xml

2 Answers 2

2

Create following xml file for add column:

Vendor/Module/view/adminhtml/layout/newsletter_subscriber_block.xml


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="adminhtml.newslettrer.subscriber.grid.columnSet">
            <block class="Magento\Backend\Block\Widget\Grid\Column">
                <arguments>
                    <argument name="header" xsi:type="string" translate="true">New Column</argument>
                    <argument name="index" xsi:type="string">subscriber_confirm_code</argument>
                    <argument name="header_css_class" xsi:type="string">col-email</argument>
                    <argument name="column_css_class" xsi:type="string">ccol-email</argument>
                </arguments>
            </block>
        </referenceBlock>
        <referenceBlock name="adminhtml.newslettrer.subscriber.grid.massaction">
            <arguments>
                <argument name="options" xsi:type="array">
                    <item name="unsubscribeTEST" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Unsubscribe TEST</item>
                        <item name="url" xsi:type="string">*/*/massUnsubscribe</item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Here index should be table column name.


<argument name="index" xsi:type="string">subscriber_confirm_code</argument>

5
  • How we can add New mass action in same as i have try to do in this way ? <referenceBlock name="adminhtml.newslettrer.subscriber.grid.massaction"> <block class= "Magento\Backend\Block\Widget\Grid\Massaction"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="type" xsi:type="string">unique_name</item> <item name="label" xsi:type="string" translate="true">Do massaction</item> <item name="url" xsi:type="url" path="atwix_testattribute/order/domassaction"/> </item> </argument> </block> </referenceBlock>
    – John
    May 28, 2016 at 9:09
  • yes, check updated answer.
    – Sohel Rana
    May 28, 2016 at 9:54
  • I have added the same code as you have suggested above for mass action.......... <item name="url" xsi:type="string">*/*/massUnsubscribe</item>.. as.. <item name="url" xsi:type="string">vendorname_modulename/foldername/massTets</item> "massTest" is my new action............I have added the controller file in controller Vendorname\Modulename\Controller\Adminhtml\Foldername\MassTest extends \Magento\Newsletter\Controller\Adminhtml\Subscriber........... every time page goes to 404.............In browser url comes correct.........so can you please let me know what is going wrong?
    – John
    May 28, 2016 at 18:29
  • any updates on above comment "I have added............................."
    – John
    Jun 2, 2016 at 6:37
  • show your routes.xml. vendorname_modulename/foldername/massTets should be 'frontName/[foldername]/massTets'.
    – Sohel Rana
    Jun 2, 2016 at 7:43
0

You can column from that file "newsletter_subscriber_block.xm" you can see code like for add column:

<block class="Magento\Backend\Block\Widget\Grid\Column" as="firstname">
    <arguments>
        <argument name="header" xsi:type="string" translate="true">Customer First Name</argument>
        <argument name="index" xsi:type="string">firstname</argument>
        <argument name="default" xsi:type="string">----</argument>
        <argument name="header_css_class" xsi:type="string">col-first-name</argument>
        <argument name="column_css_class" xsi:type="string">col-first-name</argument>
    </arguments>
</block>
2
  • Thanks for comment but what will be the file path will it be like this app\code\Vendorname\Modulename\view\adminhtml\layout\newsletter_subscriber_block.xml ? do we need to override or simply copy the file from vendor\magento\module-newsletter\view\adminhtml\layout\newsletter_subscriber.xml and copy in app\code\Vendorname\Modulename\view\adminhtml\layout\newsletter_subscriber_block.xml ? and added the new column in my file
    – John
    May 28, 2016 at 7:28
  • For override xml file please check :codedump.io/share/eHbvu0qLWInj/1/…
    – user15917
    May 28, 2016 at 7:36

Your Answer

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

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