How to Implement massactions in grid using ui_component magento2. I have created my ui_component and need to implement massactions. I have also created controllers for the required paths. But, somehow it is just not working. I'm using magento 2.1 C.E.
ui_component/test_grid.xml
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="selectProvider" xsi:type="string">test_grid.test_grid.test_grid_columns.ids</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
<item name="indexField" xsi:type="string">entity_id</item>
</item>
</argument>
<action name="accept">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">accepted</item>
<item name="label" xsi:type="string" translate="true">Accept</item>
<item name="url" xsi:type="string">test/Index/Massaccept</item>
</item>
</argument>
</action>
</massaction>
Index/Massaccept.php
<?php
namespace Vendor\Module\Controller\Adminhtml\Index;
use \Vendor\Module\Model\TestFactory;
class Massaccept extends \Magento\Backend\App\Action {
protected $resultPageFactory = false;
protected $_fasctcureFactory;
public function __construct(
TestFactory $testFactory,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Backend\App\Action\Context $context
) {
$this->_testFactory = $testFactory;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute() {
die("working");
$ids = $this->getRequest()->getParam('id');
$model = $this->_testFactory->create();
foreach($ids as $id) {
$model->load($id);
$model->getStatus();
$model->setStatus('Processing');
$model->save();
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setRefererOrBaseUrl();
return $resultRedirect;
}
}
My controllers are in the path:
Vendor/Module/Controller/Adminhtml/Index/Massaccept.php
Vendor/Module/Controller/Adminhtml/Index/Massreject.php
The mass actions are visible on the grid, but are not redirecting anywhere.Redirect is not working for using above code.
All I'm getting is this error:
Uncaught TypeError: Cannot read property 'total' of undefined
in massactions.js:52