سؤال

I'm having some trouble getting "Select All" working properly for a custom grid.

I have a massDelete action working and deleting multiple items. I have a multiselect column which, after I run a "Select All", displays the fact that the full count is selected (It says that the full count of 150 oo so items are selected). The problem is that when I run the massDelete action after a "Select All", only the 20 or so items on the current page are deleted.

Here is my Mass Action:

<massaction name="listing_massaction">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="selectProvider" xsi:type="string">rule_listing.rule_listing.rule_listing_columns.ids</item>
            <item name="indexField" xsi:type="string">rule_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="*/*/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>
</massaction>

Here is the selectionsColumn

<selectionsColumn name="ids">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="indexField" xsi:type="string">rule_id</item>
        </item>
    </argument>
</selectionsColumn>

My controller is using the following code:

$this->filter->getCollection($this->collectionFactory->create())
foreach ($collection as $model) {
    $model->delete();
}

I have checked the values that are being POSTed to the controller. There is no difference between what is POSTed after doing a "Select All" compared to selecting the first page.

Am I missing something?

هل كانت مفيدة؟

المحلول

This is an upstream bug:

https://github.com/magento/magento2/issues/23110

Solution: https://github.com/magento/magento2/pull/22704/commits/595a7a8f56571a5bd2753096bef9db27d46020ff

app/code/Magento/Ui/view/base/web/js/grid/massactions.js - remove the following lines (156-160):

if (itemsType === 'excluded' && data.selected && data.selected.length) {
  itemsType = 'selected';
  data[itemsType] = _.difference(data.selected, data.excluded);
}

نصائح أخرى

This has been fixed in Magento 2.3.3 where you can now do a mass action on more than 200 items.

So long as you have selectedProvider configured correctly there should be no problems getting ids in the controller now.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top