0

I m creating a custom module and everything is working fine except the mass actions. I know that i must have missed some setting ;) but i cant figure out where. Here is the grid config code:

service_index_listing.service_index_listing_data_source service_index_listing.service_index_listing_data_source service_columns add Add New Service primary //new ServiceGridDataProvider service_index_listing_data_source block_id id Magento_Ui/js/grid/provider ui/grid/toolbar Magento_Ui/js/grid/controls/bookmarks/bookmarks dataGridActions service_index_listing service_index_listing.service_index_listing.service_columns Magento_Ui/js/grid/controls/columns dataGridActions Magento_Ui/js/grid/search/search dataGridFilters service_index_listing.service_index_listing_data_source service_index_listing.service_index_listing.listing_top.listing_filters_chips service_index_listing.service_index_listing.listing_top.bookmarks current.search

    <filters name="listing_filters">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="displayArea" xsi:type="string">dataGridFilters</item>
                <item name="dataScope" xsi:type="string">filters</item>
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current.filters</item>
                </item>
                <item name="childDefaults" xsi:type="array">
                    <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.listing_filters</item>
                    <item name="imports" xsi:type="array">
                        <item name="visible" xsi:type="string">service_index_listing.service_index_listing.listing_top.bookmarks:current.columns.${ $.index }.visible</item>
                    </item>
                </item>
            </item>
        </argument>
        <filterRange name="service_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataScope" xsi:type="string">service_id</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                    <item name="childDefaults" xsi:type="array">
                        <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.listing_filters</item>
                    </item>
                </item>
            </argument>
            <filterInput name="from">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="dataScope" xsi:type="string">from</item>
                        <item name="label" xsi:type="string" translate="true">from</item>
                        <item name="placeholder" xsi:type="string" translate="true">From</item>
                    </item>
                </argument>
            </filterInput>
            <filterInput name="to">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="dataScope" xsi:type="string">to</item>
                        <item name="label" xsi:type="string" translate="true">to</item>
                        <item name="placeholder" xsi:type="string" translate="true">To</item>
                    </item>
                </argument>
            </filterInput>
        </filterRange>
        <filterInput name="name">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataScope" xsi:type="string">name</item>
                    <item name="label" xsi:type="string" translate="true">Name</item>
                </item>
            </argument>
        </filterInput>        

        <filterSelect name="is_active">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataScope" xsi:type="string">is_active</item>
                    <item name="label" xsi:type="string" translate="true">Status</item>
                    <item name="caption" xsi:type="string" translate="true">Select...</item>
                    <item name="options" xsi:type="array">
                        <item name="disable" xsi:type="array">
                            <item name="value" xsi:type="string">0</item>
                            <item name="label" xsi:type="string" translate="true">Disabled</item>
                        </item>
                        <item name="enable" xsi:type="array">
                            <item name="value" xsi:type="string">1</item>
                            <item name="label" xsi:type="string" translate="true">Published</item>
                        </item>
                    </item>
                </item>
            </argument>
        </filterSelect>
        <filterRange name="creation_time" class="Magento\Ui\Component\Filters\Type\DateRange">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataScope" xsi:type="string">creation_time</item>
                    <item name="label" xsi:type="string" translate="true">Created</item>
                    <item name="childDefaults" xsi:type="array">
                        <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.listing_filters</item>
                    </item>
                </item>
            </argument>
            <filterDate name="from">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="dataScope" xsi:type="string">from</item>
                        <item name="label" xsi:type="string" translate="true">from</item>
                        <item name="placeholder" xsi:type="string" translate="true">From</item>
                        <item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
                    </item>
                </argument>
            </filterDate>
            <filterDate name="to">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="dataScope" xsi:type="string">to</item>
                        <item name="label" xsi:type="string" translate="true">to</item>
                        <item name="placeholder" xsi:type="string" translate="true">To</item>
                        <item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
                    </item>
                </argument>
            </filterDate>
        </filterRange>
        <filterRange name="update_time" class="Magento\Ui\Component\Filters\Type\DateRange">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataScope" xsi:type="string">update_time</item>
                    <item name="label" xsi:type="string" translate="true">Modified</item>
                    <item name="childDefaults" xsi:type="array">
                        <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.listing_filters</item>
                    </item>
                </item>
            </argument>
            <filterDate name="from">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="dataScope" xsi:type="string">from</item>
                        <item name="label" xsi:type="string" translate="true">from</item>
                        <item name="placeholder" xsi:type="string" translate="true">From</item>
                        <item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
                    </item>
                </argument>
            </filterDate>
            <filterDate name="to">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="dataScope" xsi:type="string">to</item>
                        <item name="label" xsi:type="string" translate="true">to</item>
                        <item name="placeholder" xsi:type="string" translate="true">To</item>
                        <item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
                    </item>
                </argument>
            </filterDate>
        </filterRange>
    </filters>

    <massaction name="listing_massaction">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="selectProvider" xsi:type="string">service_index_listing.service_index_listing.service_index_columns.ids</item>
                <item name="indexField" xsi:type="string">service_id</item>
            </item>
        </argument>
        <action name="delete">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">delete</item>
                    <item name="label" xsi:type="string" translate="true">Delete</item>
                    <item name="url" xsi:type="url" path="service/index/massDelete"/>
                    <item name="confirm" xsi:type="array">
                        <item name="title" xsi:type="string" translate="true">Delete items</item>
                        <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                    </item>
                </item>
            </argument>
        </action>
        <action name="disable">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">disable</item>
                    <item name="label" xsi:type="string" translate="true">Disable</item>
                    <item name="url" xsi:type="url" path="service/index/massDisable"/>
                </item>
            </argument>
        </action>
        <action name="enable">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">enable</item>
                    <item name="label" xsi:type="string" translate="true">Enable</item>
                    <item name="url" xsi:type="url" path="service/index/massEnable"/>
                </item>
            </argument>
        </action>
    </massaction>


    <paging name="listing_paging">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current.paging</item>
                </item>
                <item name="selectProvider" xsi:type="string">service_index_listing.service_index_listing.service_columns.ids</item>
                <item name="displayArea" xsi:type="string">bottom</item>
                <item name="options" xsi:type="array">
                    <item name="20" xsi:type="array">
                        <item name="value" xsi:type="number">20</item>
                        <item name="label" xsi:type="string" translate="true">20</item>
                    </item>
                    <item name="30" xsi:type="array">
                        <item name="value" xsi:type="number">30</item>
                        <item name="label" xsi:type="string" translate="true">30</item>
                    </item>
                    <item name="50" xsi:type="array">
                        <item name="value" xsi:type="number">50</item>
                        <item name="label" xsi:type="string" translate="true">50</item>
                    </item>
                    <item name="100" xsi:type="array">
                        <item name="value" xsi:type="number">100</item>
                        <item name="label" xsi:type="string" translate="true">100</item>
                    </item>
                    <item name="200" xsi:type="array">
                        <item name="value" xsi:type="number">200</item>
                        <item name="label" xsi:type="string" translate="true">200</item>
                    </item>
                </item>
            </item>
        </argument>
    </paging>
</container>
<columns name="service_columns">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="storageConfig" xsi:type="array">
                <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.bookmarks</item>
                <item name="namespace" xsi:type="string">current</item>
            </item>
            <item name="childDefaults" xsi:type="array">
                <item name="fieldAction" xsi:type="array">
                    <item name="provider" xsi:type="string">service_index_listing.service_index_listing.service_columns.actions</item>
                    <item name="target" xsi:type="string">applyAction</item>
                    <item name="params" xsi:type="array">
                        <item name="0" xsi:type="string">edit</item>
                        <item name="1" xsi:type="string">${ $.$data.rowIndex }</item>
                    </item>
                </item>
                <item name="controlVisibility" xsi:type="boolean">true</item>
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">service_index_listing.service_index_listing.listing_top.bookmarks</item>
                    <item name="root" xsi:type="string">columns.${ $.index }</item>
                    <item name="namespace" xsi:type="string">current.${ $.storageConfig.root}</item>
                </item>
            </item>
        </item>
    </argument>

    <selectionsColumn name="ids">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="resizeEnabled" xsi:type="boolean">false</item>
                <item name="resizeDefaultWidth" xsi:type="string">55</item>
                <item name="indexField" xsi:type="string">service_id</item>
            </item>
        </argument>
    </selectionsColumn>

    <column name="service_id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">textRange</item>
                <item name="sorting" xsi:type="string">asc</item>
                <item name="label" xsi:type="string" translate="true">ID</item>
                <item name="sortOrder" xsi:type="number">10</item>
            </item>
        </argument>
    </column>
    <column name="name">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="editor" xsi:type="array">
                    <item name="editorType" xsi:type="string">text</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
                <item name="label" xsi:type="string" translate="true">Name</item>
                <item name="sortOrder" xsi:type="number">20</item>
            </item>
        </argument>
    </column>
    <column name="shortdesc">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="editor" xsi:type="array">
                    <item name="editorType" xsi:type="string">text</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
                <item name="label" xsi:type="string" translate="true">Short Description</item>
                <item name="sortOrder" xsi:type="number">30</item>
            </item>
        </argument>
    </column>

    <column name="display_order">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="editor" xsi:type="array">
                    <item name="editorType" xsi:type="string">text</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
                <item name="label" xsi:type="string" translate="true">Display Order</item>
                <item name="sortOrder" xsi:type="number">50</item>
            </item>
        </argument>
    </column>        

    <column name="is_active">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Webilize\Service\Model\Service\Source\IsActive</item>
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">select</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                <item name="editor" xsi:type="string">select</item>
                <item name="dataType" xsi:type="string">select</item>
                <item name="label" xsi:type="string" translate="true">Status</item>
                <item name="sortOrder" xsi:type="number">60</item>
            </item>
        </argument>
    </column>
    <column name="creation_time" class="Magento\Ui\Component\Listing\Columns\Date">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">dateRange</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                <item name="dataType" xsi:type="string">date</item>
                <item name="label" xsi:type="string" translate="true">Created</item>
                <item name="sortOrder" xsi:type="number">70</item>
            </item>
        </argument>
    </column>
    <column name="update_time" class="Magento\Ui\Component\Listing\Columns\Date">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">dateRange</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                <item name="dataType" xsi:type="string">date</item>
                <item name="label" xsi:type="string" translate="true">Modified</item>
                <item name="sortOrder" xsi:type="number">80</item>
            </item>
        </argument>
    </column>
    <actionsColumn name="actions" class="Webilize\service\Ui\Component\Listing\Column\ServiceActions">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="resizeEnabled" xsi:type="boolean">false</item>
                <item name="resizeDefaultWidth" xsi:type="string">107</item>
                <item name="indexField" xsi:type="string">service_id</item>
                <item name="sortOrder" xsi:type="number">90</item>
            </item>
        </argument>
    </actionsColumn>
</columns>

And the 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">
    <preference for="Webilize\Service\Api\Data\ServiceInterface" type="Webilize\Service\Model\Service" />
    <virtualType name="ServiceGirdFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
        <arguments>
            <argument name="appliers" xsi:type="array">
                <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
                <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="ServiceGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Webilize\Service\Model\ResourceModel\Service\Collection</argument>
            <argument name="filterPool" xsi:type="object" shared="false">ServiceGirdFilterPool</argument>
        </arguments>
    </virtualType>
    <virtualType name="Webilize\Service\Model\ResourceModel\Service\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">webilize_service</argument>
            <argument name="resourceModel" xsi:type="string">Webilize\Service\Model\ResourceModel\Service</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="service_index_listing_data_source" xsi:type="string">Webilize\Service\Model\ResourceModel\Service\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
</config>

When i click on any mass action (delete, disable, enable) it returns following error:

Uncaught TypeError: Cannot read property 'total' of undefined
    at UiClass.applyAction (massactions.js:52)
    at HTMLLIElement.<anonymous> (knockout.js:3863)
    at HTMLLIElement.dispatch (jquery.js:4624)
    at HTMLLIElement.elemData.handle (jquery.js:4292)
    enter code here

I am following this blog

1

I think, that you selections provider is not correct. Try to replace this line:

<item name="selectProvider" xsi:type="string">service_index_listing.service_index_listing.service_columns.ids</item>

Because your columns component has name service_columns (<columns name="service_columns">), not service_index_columns

| improve this answer | |

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.