Zend certified PHP/Magento developer

magento 2.3 grid mass action selectAll doesnt send any id

I’ve created a grid via ui component with a mass action. I’ve also added a selections column so when the user click on one or more checkboxes, the items in the grid get selected and the mass action can be called on those items.

This work if the user selects only some records from the list, but if the user selects all the items by the action dropdown “select all”, then the mass action cannot work.

This is because different parameters are used:
– when the user checks the boxes individually, then the “selected” parameter is passed to my controller with the id selected
– when the user chooses “select all”, no “selected” parameter is passed. Instead, there is a parameter “excluded” false and no ids are passed to my controller.

Magento doesn’t need the ids when “select all” is chosen because the mass action simply loads the collection. My problem is that my grid is not related to a table, so I cannot call any model/collection. I have a custom data provider that gets the data from an external source and displays the data in the grid.

Calling the external data all over again in the mass action controller is far more expensive than simply passing the ids, so simulating the magento way of reloading the collection is not a desirable option. The best thing in my opinion would be to pass the “selected” parameter also when all items are selected with the “select all” dropdown option.

Is there a way to achive this?

My code is pretty standard:

  • the mass action and the grid is build via ui component listing:
...

  
            
                
                    my_provider.ids
                    id
                
            
            
                
                    
                        massaction_name
                        Mass Action Name
                        
                        
                            Title
                            Are you sure?
                        
                    
                
            
        
...

   
            
                
                    id
                    select
                    Magento_Ui/js/grid/columns/onoff
                
            
        
...
  • the controller retrieves the request parameters:
...
class Path extends Action implements HttpGetActionInterface, HttpPostActionInterface
...
public function execute() {
  $params = $this->getRequest()->getParams();
}
...

As I mentioned, $params returns an array “selected” with the ids or a flag set to false if “selectAll” was used for the selection:

array (
  'selected' => 
  array (
    0 => '505928',
...
array (
  'excluded' => 'false'
...

But I need the “selected” array also when the selectAll option is used. Is there a way to get it?