4

I want to export one attribute of product. For this I have to select all other attributes one by one for excluding. Can anyone please tell me How can I add the Select All option to select all the option at once for exclude.

enter image description here

  • How to export all the attibute and its options via script in magento 2 – Jaisa Jun 1 '18 at 11:21
2

Add a "select all" button beside "Reset Filter". We need add plugin to class Magento\Backend\Block\Widget\Grid\Extended with getMainButtonsHtml method. As below

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Backend\Block\Widget\Grid\Extended">
    <plugin name="VendorName_ModuleName::After" type="VendorName\ModuleName\Plugin\Block\Widget\Grid\Extended" />
</type>

Make a Extended.php file under VendorName\ModuleName\Plugin\Block\Widget\Grid path. We have written selectAll javascript function.

    public function afterGetMainButtonsHtml(\Magento\Backend\Block\Widget\Grid\Extended $subject, $result)
{

        $result .= '<button id="" title="Select All" type="button" class="action-default scalable action-reset action-tertiary" onclick="export_filter_gridJsObject.selectAll()" data-action="grid-filter-reset" data-ui-id="widget-button-3"><span>Select All</span></button>';

    return $result;

}

Now we will have to extend phtml file too. For javascript function (path :magento\module-import-export\view\adminhtml\templates\export\form\filter\after.phtml)

Add this script.

        export_filter_gridJsObject.selectAll = function () {
    // class admin__control-checkbox is selector 
        var inputs = document.getElementsByClassName("admin__control-checkbox");
        for(var i = 0; i < inputs.length; i++) {
            if(inputs[i].type == "checkbox") {
                inputs[i].checked = true;
            }
        }
    };

enter image description here

Hope this will help.

1

Which file do you put the first block of code

<config xmlns:...><type name="M..</type>

into?

For the second bit I can see where the new php goes into extended.php.

Thanks

Mike

0

We have done coding to add, "Select All" with the Export filter.

Create Czargroup\Exportproduct\etc\adminhtml\di.xml

    <?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Backend\Block\Widget\Grid\Extended">
        <plugin disabled="false" name="Czargroup_Exportproduct_Plugin_Backend_Magento_Backend_Block_Widget_Grid_Extended" sortOrder="10" type="Czargroup\Exportproduct\Plugin\Backend\Magento\Backend\Block\Widget\Grid\Extended"/>
    </type>
</config>

And Czargroup\Exportproduct\etc\module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Czargroup_Exportproduct" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Backend"/>
        </sequence>
    </module>
</config>

And Czargroup\Exportproduct\Plugin\Backend\Magento\Backend\Block\Widget\Grid\Extended.php

<?php
namespace Czargroup\Exportproduct\Plugin\Backend\Magento\Backend\Block\Widget\Grid;
class Extended
{
    public function afterGetMainButtonsHtml(
        \Magento\Backend\Block\Widget\Grid\Extended $subject,
        $result
    ) {
        $result .= '<button id="" title="Select All" type="button" class="action-default scalable action-reset action-tertiary" onclick="export_filter_gridJsObject.selectAll()" data-action="grid-filter-reset" data-ui-id="widget-button-3"><span>Select All</span></button>';

        return $result;
    }
}

And /vendor/magento/module-import-export/view/adminhtml/templates/export/form/filter/after.phtml Line 18

export_filter_gridJsObject.selectAll = function () {
            // class admin__control-checkbox is selector 
            var inputs = document.getElementsByClassName("admin__control-checkbox");
            for(var i = 0; i < inputs.length; i++) {
                if(inputs[i].type == "checkbox") {
                    inputs[i].checked = true;
                }
            }
        };

And Czargroup\Exportproduct\registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Czargroup_Exportproduct',
    __DIR__
);

And Czargroup\Exportproduct\composer.json

{
    "name": "czargroup/module-exportproduct",
    "description": "Add Select All option in Export Settings",
    "type": "magento2-module",
    "license": "proprietary",
    "authors": [
        {
            "email": "info@mage2gen.com",
            "name": "Mage2Gen"
        },
        {
            "email": "pilukamani@gmail.com",
            "name": "Pratik Kamani"
        }
    ],
    "minimum-stability": "dev",
    "require": {},
    "autoload": {
        "psr-4": {
            "Czargroup\\Exportproduct\\": ""
        },
        "files": [
            "registration.php"
        ]
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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