Mass action in custom grid block Magento 2 not showing












6














I've created a product grid block following this tutorial, right now i want to add new massAction item but the mass action field won't show up in the toolbar grid, here's the xml file:



<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
<referenceContainer name="content">
<block class="LimeLazadaBlockAdminhtmlListingproductProducts" name="lazada_listingproduct_products"/>
<action method="addTab">
<argument name="name" xsi:type="string">products_section</argument>
<argument name="block" xsi:type="array">
<item name="label" xsi:type="string">Select Products</item>
<item name="title" xsi:type="string">Select Products</item>
<item name="url" xsi:type="helper" helper="LimeLazadaHelperData::getProductsGridUrl2"></item>
<item name="class" xsi:type="string">ajax</item>
</argument>
</action>
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="export">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">export</item>
<item name="label" xsi:type="string" translate="true">Export to CSV</item>
<item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</referenceContainer>
</body>
</page>


the listingtoolbar should load the mass action but it never shows up, here's the block class code:



class Products extends MagentoBackendBlockWidgetGridExtended
{
/**
* @var MagentoCatalogModelResourceModelProductCollectionFactory
*/
protected $productCollectionFactory;

/**
* Listing factory
*
* @var ListingFactory
*/
protected $listingFactory;

/**
* @var MagentoFrameworkRegistry
*/
protected $registry;

protected $_objectManager = null;

/**
*
* @param MagentoBackendBlockTemplateContext $context
* @param MagentoBackendHelperData $backendHelper
* @param MagentoFrameworkRegistry $registry
* @param ListingFactory $attachmentFactory
* @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
* @param array $data
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoBackendHelperData $backendHelper,
MagentoFrameworkRegistry $registry,
MagentoFrameworkObjectManagerInterface $objectManager,
ListingFactory $listingFactory,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
array $data =
) {
$this->listingFactory = $listingFactory;
$this->productCollectionFactory = $productCollectionFactory;
$this->_objectManager = $objectManager;
$this->registry = $registry;
parent::__construct($context, $backendHelper, $data);
}

/**
* _construct
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('productsGrid');
$this->setDefaultSort('entity_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
if ($this->getRequest()->getParam('listing_id')) {
$this->setDefaultFilter(array('in_product' => 1));
}
}

/**
* add Column Filter To Collection
*/
protected function _addColumnFilterToCollection($column)
{
if ($column->getId() == 'in_product') {
$productIds = $this->_getSelectedProducts();

if (empty($productIds)) {
$productIds = 0;
}
if ($column->getFilter()->getValue()) {
$this->getCollection()->addFieldToFilter('entity_id', array('in' => $productIds));
} else {
if ($productIds) {
$this->getCollection()->addFieldToFilter('entity_id', array('nin' => $productIds));
}
}
} else {
parent::_addColumnFilterToCollection($column);
}

return $this;
}

/**
* prepare collection
*/
protected function _prepareCollection()
{
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('name');
$collection->addAttributeToSelect('sku');
$collection->addAttributeToSelect('price');
$this->setCollection($collection);
return parent::_prepareCollection();
}

/**
* @return $this
*/
protected function _prepareColumns()
{
/* @var $model LimeLazadaModelSlide */
$model = $this->_objectManager->get('LimeLazadaModelListing');

$this->addColumn(
'in_product',
[
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'in_product',
'align' => 'center',
'index' => 'entity_id',
'values' => $this->_getSelectedProducts(),
]
);

$this->addColumn(
'entity_id',
[
'header' => __('Product ID'),
'type' => 'number',
'index' => 'entity_id',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id',
]
);
$this->addColumn(
'name',
[
'header' => __('Name'),
'index' => 'name',
'class' => 'xxx',
'width' => '50px',
]
);
$this->addColumn(
'sku',
[
'header' => __('Sku'),
'index' => 'sku',
'class' => 'xxx',
'width' => '50px',
]
);
$this->addColumn(
'price',
[
'header' => __('Price'),
'type' => 'currency',
'index' => 'price',
'width' => '50px',
]
);

return parent::_prepareColumns();
}

/**
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('*/*/productsgrid', ['_current' => true]);
}

/**
* @param object $row
* @return string
*/
public function getRowUrl($row)
{
return '';
}

protected function _getSelectedProducts()
{
$listing = $this->getListing();
return $listing->getProducts($listing);
}

/**
* Retrieve selected products
*
* @return array
*/
public function getSelectedProducts()
{
$listing = $this->getListing();
$selected = $listing->getProducts($listing);

if (!is_array($selected)) {
$selected = ;
}
return $selected;
}

protected function getListing()
{
$listingId = $this->getRequest()->getParam('listing_id');
$listing = $this->listingFactory->create();
if ($listingId) {
$listing->load($listingId);
}
return $listing;
}

/**
* {@inheritdoc}
*/
public function canShowTab()
{
return true;
}

/**
* {@inheritdoc}
*/
public function isHidden()
{
return true;
}
}









share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    6














    I've created a product grid block following this tutorial, right now i want to add new massAction item but the mass action field won't show up in the toolbar grid, here's the xml file:



    <?xml version="1.0" ?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="styles"/>
    <body>
    <referenceContainer name="content">
    <block class="LimeLazadaBlockAdminhtmlListingproductProducts" name="lazada_listingproduct_products"/>
    <action method="addTab">
    <argument name="name" xsi:type="string">products_section</argument>
    <argument name="block" xsi:type="array">
    <item name="label" xsi:type="string">Select Products</item>
    <item name="title" xsi:type="string">Select Products</item>
    <item name="url" xsi:type="helper" helper="LimeLazadaHelperData::getProductsGridUrl2"></item>
    <item name="class" xsi:type="string">ajax</item>
    </argument>
    </action>
    <listingToolbar name="listing_top">
    <massaction name="listing_massaction">
    <action name="export">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="type" xsi:type="string">export</item>
    <item name="label" xsi:type="string" translate="true">Export to CSV</item>
    <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
    </item>
    </argument>
    </action>
    </massaction>
    </listingToolbar>
    </referenceContainer>
    </body>
    </page>


    the listingtoolbar should load the mass action but it never shows up, here's the block class code:



    class Products extends MagentoBackendBlockWidgetGridExtended
    {
    /**
    * @var MagentoCatalogModelResourceModelProductCollectionFactory
    */
    protected $productCollectionFactory;

    /**
    * Listing factory
    *
    * @var ListingFactory
    */
    protected $listingFactory;

    /**
    * @var MagentoFrameworkRegistry
    */
    protected $registry;

    protected $_objectManager = null;

    /**
    *
    * @param MagentoBackendBlockTemplateContext $context
    * @param MagentoBackendHelperData $backendHelper
    * @param MagentoFrameworkRegistry $registry
    * @param ListingFactory $attachmentFactory
    * @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
    * @param array $data
    */
    public function __construct(
    MagentoBackendBlockTemplateContext $context,
    MagentoBackendHelperData $backendHelper,
    MagentoFrameworkRegistry $registry,
    MagentoFrameworkObjectManagerInterface $objectManager,
    ListingFactory $listingFactory,
    MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
    array $data =
    ) {
    $this->listingFactory = $listingFactory;
    $this->productCollectionFactory = $productCollectionFactory;
    $this->_objectManager = $objectManager;
    $this->registry = $registry;
    parent::__construct($context, $backendHelper, $data);
    }

    /**
    * _construct
    * @return void
    */
    protected function _construct()
    {
    parent::_construct();
    $this->setId('productsGrid');
    $this->setDefaultSort('entity_id');
    $this->setDefaultDir('DESC');
    $this->setSaveParametersInSession(true);
    $this->setUseAjax(true);
    if ($this->getRequest()->getParam('listing_id')) {
    $this->setDefaultFilter(array('in_product' => 1));
    }
    }

    /**
    * add Column Filter To Collection
    */
    protected function _addColumnFilterToCollection($column)
    {
    if ($column->getId() == 'in_product') {
    $productIds = $this->_getSelectedProducts();

    if (empty($productIds)) {
    $productIds = 0;
    }
    if ($column->getFilter()->getValue()) {
    $this->getCollection()->addFieldToFilter('entity_id', array('in' => $productIds));
    } else {
    if ($productIds) {
    $this->getCollection()->addFieldToFilter('entity_id', array('nin' => $productIds));
    }
    }
    } else {
    parent::_addColumnFilterToCollection($column);
    }

    return $this;
    }

    /**
    * prepare collection
    */
    protected function _prepareCollection()
    {
    $collection = $this->productCollectionFactory->create();
    $collection->addAttributeToSelect('name');
    $collection->addAttributeToSelect('sku');
    $collection->addAttributeToSelect('price');
    $this->setCollection($collection);
    return parent::_prepareCollection();
    }

    /**
    * @return $this
    */
    protected function _prepareColumns()
    {
    /* @var $model LimeLazadaModelSlide */
    $model = $this->_objectManager->get('LimeLazadaModelListing');

    $this->addColumn(
    'in_product',
    [
    'header_css_class' => 'a-center',
    'type' => 'checkbox',
    'name' => 'in_product',
    'align' => 'center',
    'index' => 'entity_id',
    'values' => $this->_getSelectedProducts(),
    ]
    );

    $this->addColumn(
    'entity_id',
    [
    'header' => __('Product ID'),
    'type' => 'number',
    'index' => 'entity_id',
    'header_css_class' => 'col-id',
    'column_css_class' => 'col-id',
    ]
    );
    $this->addColumn(
    'name',
    [
    'header' => __('Name'),
    'index' => 'name',
    'class' => 'xxx',
    'width' => '50px',
    ]
    );
    $this->addColumn(
    'sku',
    [
    'header' => __('Sku'),
    'index' => 'sku',
    'class' => 'xxx',
    'width' => '50px',
    ]
    );
    $this->addColumn(
    'price',
    [
    'header' => __('Price'),
    'type' => 'currency',
    'index' => 'price',
    'width' => '50px',
    ]
    );

    return parent::_prepareColumns();
    }

    /**
    * @return string
    */
    public function getGridUrl()
    {
    return $this->getUrl('*/*/productsgrid', ['_current' => true]);
    }

    /**
    * @param object $row
    * @return string
    */
    public function getRowUrl($row)
    {
    return '';
    }

    protected function _getSelectedProducts()
    {
    $listing = $this->getListing();
    return $listing->getProducts($listing);
    }

    /**
    * Retrieve selected products
    *
    * @return array
    */
    public function getSelectedProducts()
    {
    $listing = $this->getListing();
    $selected = $listing->getProducts($listing);

    if (!is_array($selected)) {
    $selected = ;
    }
    return $selected;
    }

    protected function getListing()
    {
    $listingId = $this->getRequest()->getParam('listing_id');
    $listing = $this->listingFactory->create();
    if ($listingId) {
    $listing->load($listingId);
    }
    return $listing;
    }

    /**
    * {@inheritdoc}
    */
    public function canShowTab()
    {
    return true;
    }

    /**
    * {@inheritdoc}
    */
    public function isHidden()
    {
    return true;
    }
    }









    share|improve this question
















    bumped to the homepage by Community yesterday


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      6












      6








      6







      I've created a product grid block following this tutorial, right now i want to add new massAction item but the mass action field won't show up in the toolbar grid, here's the xml file:



      <?xml version="1.0" ?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <update handle="styles"/>
      <body>
      <referenceContainer name="content">
      <block class="LimeLazadaBlockAdminhtmlListingproductProducts" name="lazada_listingproduct_products"/>
      <action method="addTab">
      <argument name="name" xsi:type="string">products_section</argument>
      <argument name="block" xsi:type="array">
      <item name="label" xsi:type="string">Select Products</item>
      <item name="title" xsi:type="string">Select Products</item>
      <item name="url" xsi:type="helper" helper="LimeLazadaHelperData::getProductsGridUrl2"></item>
      <item name="class" xsi:type="string">ajax</item>
      </argument>
      </action>
      <listingToolbar name="listing_top">
      <massaction name="listing_massaction">
      <action name="export">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="type" xsi:type="string">export</item>
      <item name="label" xsi:type="string" translate="true">Export to CSV</item>
      <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
      </item>
      </argument>
      </action>
      </massaction>
      </listingToolbar>
      </referenceContainer>
      </body>
      </page>


      the listingtoolbar should load the mass action but it never shows up, here's the block class code:



      class Products extends MagentoBackendBlockWidgetGridExtended
      {
      /**
      * @var MagentoCatalogModelResourceModelProductCollectionFactory
      */
      protected $productCollectionFactory;

      /**
      * Listing factory
      *
      * @var ListingFactory
      */
      protected $listingFactory;

      /**
      * @var MagentoFrameworkRegistry
      */
      protected $registry;

      protected $_objectManager = null;

      /**
      *
      * @param MagentoBackendBlockTemplateContext $context
      * @param MagentoBackendHelperData $backendHelper
      * @param MagentoFrameworkRegistry $registry
      * @param ListingFactory $attachmentFactory
      * @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
      * @param array $data
      */
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      MagentoBackendHelperData $backendHelper,
      MagentoFrameworkRegistry $registry,
      MagentoFrameworkObjectManagerInterface $objectManager,
      ListingFactory $listingFactory,
      MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
      array $data =
      ) {
      $this->listingFactory = $listingFactory;
      $this->productCollectionFactory = $productCollectionFactory;
      $this->_objectManager = $objectManager;
      $this->registry = $registry;
      parent::__construct($context, $backendHelper, $data);
      }

      /**
      * _construct
      * @return void
      */
      protected function _construct()
      {
      parent::_construct();
      $this->setId('productsGrid');
      $this->setDefaultSort('entity_id');
      $this->setDefaultDir('DESC');
      $this->setSaveParametersInSession(true);
      $this->setUseAjax(true);
      if ($this->getRequest()->getParam('listing_id')) {
      $this->setDefaultFilter(array('in_product' => 1));
      }
      }

      /**
      * add Column Filter To Collection
      */
      protected function _addColumnFilterToCollection($column)
      {
      if ($column->getId() == 'in_product') {
      $productIds = $this->_getSelectedProducts();

      if (empty($productIds)) {
      $productIds = 0;
      }
      if ($column->getFilter()->getValue()) {
      $this->getCollection()->addFieldToFilter('entity_id', array('in' => $productIds));
      } else {
      if ($productIds) {
      $this->getCollection()->addFieldToFilter('entity_id', array('nin' => $productIds));
      }
      }
      } else {
      parent::_addColumnFilterToCollection($column);
      }

      return $this;
      }

      /**
      * prepare collection
      */
      protected function _prepareCollection()
      {
      $collection = $this->productCollectionFactory->create();
      $collection->addAttributeToSelect('name');
      $collection->addAttributeToSelect('sku');
      $collection->addAttributeToSelect('price');
      $this->setCollection($collection);
      return parent::_prepareCollection();
      }

      /**
      * @return $this
      */
      protected function _prepareColumns()
      {
      /* @var $model LimeLazadaModelSlide */
      $model = $this->_objectManager->get('LimeLazadaModelListing');

      $this->addColumn(
      'in_product',
      [
      'header_css_class' => 'a-center',
      'type' => 'checkbox',
      'name' => 'in_product',
      'align' => 'center',
      'index' => 'entity_id',
      'values' => $this->_getSelectedProducts(),
      ]
      );

      $this->addColumn(
      'entity_id',
      [
      'header' => __('Product ID'),
      'type' => 'number',
      'index' => 'entity_id',
      'header_css_class' => 'col-id',
      'column_css_class' => 'col-id',
      ]
      );
      $this->addColumn(
      'name',
      [
      'header' => __('Name'),
      'index' => 'name',
      'class' => 'xxx',
      'width' => '50px',
      ]
      );
      $this->addColumn(
      'sku',
      [
      'header' => __('Sku'),
      'index' => 'sku',
      'class' => 'xxx',
      'width' => '50px',
      ]
      );
      $this->addColumn(
      'price',
      [
      'header' => __('Price'),
      'type' => 'currency',
      'index' => 'price',
      'width' => '50px',
      ]
      );

      return parent::_prepareColumns();
      }

      /**
      * @return string
      */
      public function getGridUrl()
      {
      return $this->getUrl('*/*/productsgrid', ['_current' => true]);
      }

      /**
      * @param object $row
      * @return string
      */
      public function getRowUrl($row)
      {
      return '';
      }

      protected function _getSelectedProducts()
      {
      $listing = $this->getListing();
      return $listing->getProducts($listing);
      }

      /**
      * Retrieve selected products
      *
      * @return array
      */
      public function getSelectedProducts()
      {
      $listing = $this->getListing();
      $selected = $listing->getProducts($listing);

      if (!is_array($selected)) {
      $selected = ;
      }
      return $selected;
      }

      protected function getListing()
      {
      $listingId = $this->getRequest()->getParam('listing_id');
      $listing = $this->listingFactory->create();
      if ($listingId) {
      $listing->load($listingId);
      }
      return $listing;
      }

      /**
      * {@inheritdoc}
      */
      public function canShowTab()
      {
      return true;
      }

      /**
      * {@inheritdoc}
      */
      public function isHidden()
      {
      return true;
      }
      }









      share|improve this question















      I've created a product grid block following this tutorial, right now i want to add new massAction item but the mass action field won't show up in the toolbar grid, here's the xml file:



      <?xml version="1.0" ?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <update handle="styles"/>
      <body>
      <referenceContainer name="content">
      <block class="LimeLazadaBlockAdminhtmlListingproductProducts" name="lazada_listingproduct_products"/>
      <action method="addTab">
      <argument name="name" xsi:type="string">products_section</argument>
      <argument name="block" xsi:type="array">
      <item name="label" xsi:type="string">Select Products</item>
      <item name="title" xsi:type="string">Select Products</item>
      <item name="url" xsi:type="helper" helper="LimeLazadaHelperData::getProductsGridUrl2"></item>
      <item name="class" xsi:type="string">ajax</item>
      </argument>
      </action>
      <listingToolbar name="listing_top">
      <massaction name="listing_massaction">
      <action name="export">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="type" xsi:type="string">export</item>
      <item name="label" xsi:type="string" translate="true">Export to CSV</item>
      <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
      </item>
      </argument>
      </action>
      </massaction>
      </listingToolbar>
      </referenceContainer>
      </body>
      </page>


      the listingtoolbar should load the mass action but it never shows up, here's the block class code:



      class Products extends MagentoBackendBlockWidgetGridExtended
      {
      /**
      * @var MagentoCatalogModelResourceModelProductCollectionFactory
      */
      protected $productCollectionFactory;

      /**
      * Listing factory
      *
      * @var ListingFactory
      */
      protected $listingFactory;

      /**
      * @var MagentoFrameworkRegistry
      */
      protected $registry;

      protected $_objectManager = null;

      /**
      *
      * @param MagentoBackendBlockTemplateContext $context
      * @param MagentoBackendHelperData $backendHelper
      * @param MagentoFrameworkRegistry $registry
      * @param ListingFactory $attachmentFactory
      * @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
      * @param array $data
      */
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      MagentoBackendHelperData $backendHelper,
      MagentoFrameworkRegistry $registry,
      MagentoFrameworkObjectManagerInterface $objectManager,
      ListingFactory $listingFactory,
      MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
      array $data =
      ) {
      $this->listingFactory = $listingFactory;
      $this->productCollectionFactory = $productCollectionFactory;
      $this->_objectManager = $objectManager;
      $this->registry = $registry;
      parent::__construct($context, $backendHelper, $data);
      }

      /**
      * _construct
      * @return void
      */
      protected function _construct()
      {
      parent::_construct();
      $this->setId('productsGrid');
      $this->setDefaultSort('entity_id');
      $this->setDefaultDir('DESC');
      $this->setSaveParametersInSession(true);
      $this->setUseAjax(true);
      if ($this->getRequest()->getParam('listing_id')) {
      $this->setDefaultFilter(array('in_product' => 1));
      }
      }

      /**
      * add Column Filter To Collection
      */
      protected function _addColumnFilterToCollection($column)
      {
      if ($column->getId() == 'in_product') {
      $productIds = $this->_getSelectedProducts();

      if (empty($productIds)) {
      $productIds = 0;
      }
      if ($column->getFilter()->getValue()) {
      $this->getCollection()->addFieldToFilter('entity_id', array('in' => $productIds));
      } else {
      if ($productIds) {
      $this->getCollection()->addFieldToFilter('entity_id', array('nin' => $productIds));
      }
      }
      } else {
      parent::_addColumnFilterToCollection($column);
      }

      return $this;
      }

      /**
      * prepare collection
      */
      protected function _prepareCollection()
      {
      $collection = $this->productCollectionFactory->create();
      $collection->addAttributeToSelect('name');
      $collection->addAttributeToSelect('sku');
      $collection->addAttributeToSelect('price');
      $this->setCollection($collection);
      return parent::_prepareCollection();
      }

      /**
      * @return $this
      */
      protected function _prepareColumns()
      {
      /* @var $model LimeLazadaModelSlide */
      $model = $this->_objectManager->get('LimeLazadaModelListing');

      $this->addColumn(
      'in_product',
      [
      'header_css_class' => 'a-center',
      'type' => 'checkbox',
      'name' => 'in_product',
      'align' => 'center',
      'index' => 'entity_id',
      'values' => $this->_getSelectedProducts(),
      ]
      );

      $this->addColumn(
      'entity_id',
      [
      'header' => __('Product ID'),
      'type' => 'number',
      'index' => 'entity_id',
      'header_css_class' => 'col-id',
      'column_css_class' => 'col-id',
      ]
      );
      $this->addColumn(
      'name',
      [
      'header' => __('Name'),
      'index' => 'name',
      'class' => 'xxx',
      'width' => '50px',
      ]
      );
      $this->addColumn(
      'sku',
      [
      'header' => __('Sku'),
      'index' => 'sku',
      'class' => 'xxx',
      'width' => '50px',
      ]
      );
      $this->addColumn(
      'price',
      [
      'header' => __('Price'),
      'type' => 'currency',
      'index' => 'price',
      'width' => '50px',
      ]
      );

      return parent::_prepareColumns();
      }

      /**
      * @return string
      */
      public function getGridUrl()
      {
      return $this->getUrl('*/*/productsgrid', ['_current' => true]);
      }

      /**
      * @param object $row
      * @return string
      */
      public function getRowUrl($row)
      {
      return '';
      }

      protected function _getSelectedProducts()
      {
      $listing = $this->getListing();
      return $listing->getProducts($listing);
      }

      /**
      * Retrieve selected products
      *
      * @return array
      */
      public function getSelectedProducts()
      {
      $listing = $this->getListing();
      $selected = $listing->getProducts($listing);

      if (!is_array($selected)) {
      $selected = ;
      }
      return $selected;
      }

      protected function getListing()
      {
      $listingId = $this->getRequest()->getParam('listing_id');
      $listing = $this->listingFactory->create();
      if ($listingId) {
      $listing->load($listingId);
      }
      return $listing;
      }

      /**
      * {@inheritdoc}
      */
      public function canShowTab()
      {
      return true;
      }

      /**
      * {@inheritdoc}
      */
      public function isHidden()
      {
      return true;
      }
      }






      magento2 magento-2.1 adminhtml grid massaction






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 13 '17 at 10:13









      Raphael at Digital Pianism

      53.3k19111269




      53.3k19111269










      asked Mar 13 '17 at 10:06









      simple guysimple guy

      1,04921241




      1,04921241





      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It's because your layout file is a mix between standard grid system and the UI Component system.



          You need to replace the following code:



                  <listingToolbar name="listing_top">
          <massaction name="listing_massaction">
          <action name="export">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="type" xsi:type="string">export</item>
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </action>
          </massaction>
          </listingToolbar>


          With:



          <referenceBlock name="lazada_listingproduct_products">
          <block class="MagentoBackendBlockWidgetGridMassaction" name="adminhtml.indexer.grid.grid.massaction" as="grid.massaction">
          <arguments>
          <argument name="massaction_id_field" xsi:type="string">entity_id</argument>
          <argument name="form_field_name" xsi:type="string">entity_ids</argument>
          <argument name="use_select_all" xsi:type="string">1</argument>
          <argument name="options" xsi:type="array">
          <item name="export" xsi:type="array">
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </arguments>
          </block>
          </referenceBlock>


          Alternatively, you can add the massaction in pure PHP by adding the following method to your grid block file:



          protected function _prepareMassaction()
          {
          $this->setMassactionIdField('entity_id');
          $this->getMassactionBlock()->setFormFieldName('walltwotime');

          $this->getMassactionBlock()->addItem(
          'export',
          [
          'label' => __('Export To CSV'),
          'url' => $this->getUrl('productExport/productexport/exportcsv')
          ]
          );

          return $this;
          }





          share|improve this answer



















          • 1




            by replacing with those code i got blank page, and when i check the apache2 error.log i got this: PHP Fatal error: Uncaught Error: Call to a member function getHtmlId() on boolean in /var/www/test/vendor/magento/module-backend/Block/Widget/Grid/Massaction/AbstractMassaction.php:278nStack trace:n#0 /var/www/test/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/massaction.phtml(11)
            – simple guy
            Mar 13 '17 at 10:21












          • @simpleguy check my updated answer
            – Raphael at Digital Pianism
            Mar 13 '17 at 10:27










          • @RapahelAtDigitalPianism it still not showing, and now there are two checkboxes for massAction
            – simple guy
            Mar 13 '17 at 11:43










          • is there a way to add the mass action not via xml?
            – simple guy
            Mar 14 '17 at 2:14










          • @simpleguy yes see my edited answer
            – Raphael at Digital Pianism
            Mar 14 '17 at 7:56











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f164035%2fmass-action-in-custom-grid-block-magento-2-not-showing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It's because your layout file is a mix between standard grid system and the UI Component system.



          You need to replace the following code:



                  <listingToolbar name="listing_top">
          <massaction name="listing_massaction">
          <action name="export">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="type" xsi:type="string">export</item>
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </action>
          </massaction>
          </listingToolbar>


          With:



          <referenceBlock name="lazada_listingproduct_products">
          <block class="MagentoBackendBlockWidgetGridMassaction" name="adminhtml.indexer.grid.grid.massaction" as="grid.massaction">
          <arguments>
          <argument name="massaction_id_field" xsi:type="string">entity_id</argument>
          <argument name="form_field_name" xsi:type="string">entity_ids</argument>
          <argument name="use_select_all" xsi:type="string">1</argument>
          <argument name="options" xsi:type="array">
          <item name="export" xsi:type="array">
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </arguments>
          </block>
          </referenceBlock>


          Alternatively, you can add the massaction in pure PHP by adding the following method to your grid block file:



          protected function _prepareMassaction()
          {
          $this->setMassactionIdField('entity_id');
          $this->getMassactionBlock()->setFormFieldName('walltwotime');

          $this->getMassactionBlock()->addItem(
          'export',
          [
          'label' => __('Export To CSV'),
          'url' => $this->getUrl('productExport/productexport/exportcsv')
          ]
          );

          return $this;
          }





          share|improve this answer



















          • 1




            by replacing with those code i got blank page, and when i check the apache2 error.log i got this: PHP Fatal error: Uncaught Error: Call to a member function getHtmlId() on boolean in /var/www/test/vendor/magento/module-backend/Block/Widget/Grid/Massaction/AbstractMassaction.php:278nStack trace:n#0 /var/www/test/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/massaction.phtml(11)
            – simple guy
            Mar 13 '17 at 10:21












          • @simpleguy check my updated answer
            – Raphael at Digital Pianism
            Mar 13 '17 at 10:27










          • @RapahelAtDigitalPianism it still not showing, and now there are two checkboxes for massAction
            – simple guy
            Mar 13 '17 at 11:43










          • is there a way to add the mass action not via xml?
            – simple guy
            Mar 14 '17 at 2:14










          • @simpleguy yes see my edited answer
            – Raphael at Digital Pianism
            Mar 14 '17 at 7:56
















          0














          It's because your layout file is a mix between standard grid system and the UI Component system.



          You need to replace the following code:



                  <listingToolbar name="listing_top">
          <massaction name="listing_massaction">
          <action name="export">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="type" xsi:type="string">export</item>
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </action>
          </massaction>
          </listingToolbar>


          With:



          <referenceBlock name="lazada_listingproduct_products">
          <block class="MagentoBackendBlockWidgetGridMassaction" name="adminhtml.indexer.grid.grid.massaction" as="grid.massaction">
          <arguments>
          <argument name="massaction_id_field" xsi:type="string">entity_id</argument>
          <argument name="form_field_name" xsi:type="string">entity_ids</argument>
          <argument name="use_select_all" xsi:type="string">1</argument>
          <argument name="options" xsi:type="array">
          <item name="export" xsi:type="array">
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </arguments>
          </block>
          </referenceBlock>


          Alternatively, you can add the massaction in pure PHP by adding the following method to your grid block file:



          protected function _prepareMassaction()
          {
          $this->setMassactionIdField('entity_id');
          $this->getMassactionBlock()->setFormFieldName('walltwotime');

          $this->getMassactionBlock()->addItem(
          'export',
          [
          'label' => __('Export To CSV'),
          'url' => $this->getUrl('productExport/productexport/exportcsv')
          ]
          );

          return $this;
          }





          share|improve this answer



















          • 1




            by replacing with those code i got blank page, and when i check the apache2 error.log i got this: PHP Fatal error: Uncaught Error: Call to a member function getHtmlId() on boolean in /var/www/test/vendor/magento/module-backend/Block/Widget/Grid/Massaction/AbstractMassaction.php:278nStack trace:n#0 /var/www/test/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/massaction.phtml(11)
            – simple guy
            Mar 13 '17 at 10:21












          • @simpleguy check my updated answer
            – Raphael at Digital Pianism
            Mar 13 '17 at 10:27










          • @RapahelAtDigitalPianism it still not showing, and now there are two checkboxes for massAction
            – simple guy
            Mar 13 '17 at 11:43










          • is there a way to add the mass action not via xml?
            – simple guy
            Mar 14 '17 at 2:14










          • @simpleguy yes see my edited answer
            – Raphael at Digital Pianism
            Mar 14 '17 at 7:56














          0












          0








          0






          It's because your layout file is a mix between standard grid system and the UI Component system.



          You need to replace the following code:



                  <listingToolbar name="listing_top">
          <massaction name="listing_massaction">
          <action name="export">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="type" xsi:type="string">export</item>
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </action>
          </massaction>
          </listingToolbar>


          With:



          <referenceBlock name="lazada_listingproduct_products">
          <block class="MagentoBackendBlockWidgetGridMassaction" name="adminhtml.indexer.grid.grid.massaction" as="grid.massaction">
          <arguments>
          <argument name="massaction_id_field" xsi:type="string">entity_id</argument>
          <argument name="form_field_name" xsi:type="string">entity_ids</argument>
          <argument name="use_select_all" xsi:type="string">1</argument>
          <argument name="options" xsi:type="array">
          <item name="export" xsi:type="array">
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </arguments>
          </block>
          </referenceBlock>


          Alternatively, you can add the massaction in pure PHP by adding the following method to your grid block file:



          protected function _prepareMassaction()
          {
          $this->setMassactionIdField('entity_id');
          $this->getMassactionBlock()->setFormFieldName('walltwotime');

          $this->getMassactionBlock()->addItem(
          'export',
          [
          'label' => __('Export To CSV'),
          'url' => $this->getUrl('productExport/productexport/exportcsv')
          ]
          );

          return $this;
          }





          share|improve this answer














          It's because your layout file is a mix between standard grid system and the UI Component system.



          You need to replace the following code:



                  <listingToolbar name="listing_top">
          <massaction name="listing_massaction">
          <action name="export">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="type" xsi:type="string">export</item>
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </action>
          </massaction>
          </listingToolbar>


          With:



          <referenceBlock name="lazada_listingproduct_products">
          <block class="MagentoBackendBlockWidgetGridMassaction" name="adminhtml.indexer.grid.grid.massaction" as="grid.massaction">
          <arguments>
          <argument name="massaction_id_field" xsi:type="string">entity_id</argument>
          <argument name="form_field_name" xsi:type="string">entity_ids</argument>
          <argument name="use_select_all" xsi:type="string">1</argument>
          <argument name="options" xsi:type="array">
          <item name="export" xsi:type="array">
          <item name="label" xsi:type="string" translate="true">Export to CSV</item>
          <item name="url" xsi:type="string">productExport/productexport/exportCsv</item>
          </item>
          </argument>
          </arguments>
          </block>
          </referenceBlock>


          Alternatively, you can add the massaction in pure PHP by adding the following method to your grid block file:



          protected function _prepareMassaction()
          {
          $this->setMassactionIdField('entity_id');
          $this->getMassactionBlock()->setFormFieldName('walltwotime');

          $this->getMassactionBlock()->addItem(
          'export',
          [
          'label' => __('Export To CSV'),
          'url' => $this->getUrl('productExport/productexport/exportcsv')
          ]
          );

          return $this;
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 14 '17 at 7:55

























          answered Mar 13 '17 at 10:12









          Raphael at Digital PianismRaphael at Digital Pianism

          53.3k19111269




          53.3k19111269








          • 1




            by replacing with those code i got blank page, and when i check the apache2 error.log i got this: PHP Fatal error: Uncaught Error: Call to a member function getHtmlId() on boolean in /var/www/test/vendor/magento/module-backend/Block/Widget/Grid/Massaction/AbstractMassaction.php:278nStack trace:n#0 /var/www/test/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/massaction.phtml(11)
            – simple guy
            Mar 13 '17 at 10:21












          • @simpleguy check my updated answer
            – Raphael at Digital Pianism
            Mar 13 '17 at 10:27










          • @RapahelAtDigitalPianism it still not showing, and now there are two checkboxes for massAction
            – simple guy
            Mar 13 '17 at 11:43










          • is there a way to add the mass action not via xml?
            – simple guy
            Mar 14 '17 at 2:14










          • @simpleguy yes see my edited answer
            – Raphael at Digital Pianism
            Mar 14 '17 at 7:56














          • 1




            by replacing with those code i got blank page, and when i check the apache2 error.log i got this: PHP Fatal error: Uncaught Error: Call to a member function getHtmlId() on boolean in /var/www/test/vendor/magento/module-backend/Block/Widget/Grid/Massaction/AbstractMassaction.php:278nStack trace:n#0 /var/www/test/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/massaction.phtml(11)
            – simple guy
            Mar 13 '17 at 10:21












          • @simpleguy check my updated answer
            – Raphael at Digital Pianism
            Mar 13 '17 at 10:27










          • @RapahelAtDigitalPianism it still not showing, and now there are two checkboxes for massAction
            – simple guy
            Mar 13 '17 at 11:43










          • is there a way to add the mass action not via xml?
            – simple guy
            Mar 14 '17 at 2:14










          • @simpleguy yes see my edited answer
            – Raphael at Digital Pianism
            Mar 14 '17 at 7:56








          1




          1




          by replacing with those code i got blank page, and when i check the apache2 error.log i got this: PHP Fatal error: Uncaught Error: Call to a member function getHtmlId() on boolean in /var/www/test/vendor/magento/module-backend/Block/Widget/Grid/Massaction/AbstractMassaction.php:278nStack trace:n#0 /var/www/test/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/massaction.phtml(11)
          – simple guy
          Mar 13 '17 at 10:21






          by replacing with those code i got blank page, and when i check the apache2 error.log i got this: PHP Fatal error: Uncaught Error: Call to a member function getHtmlId() on boolean in /var/www/test/vendor/magento/module-backend/Block/Widget/Grid/Massaction/AbstractMassaction.php:278nStack trace:n#0 /var/www/test/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/massaction.phtml(11)
          – simple guy
          Mar 13 '17 at 10:21














          @simpleguy check my updated answer
          – Raphael at Digital Pianism
          Mar 13 '17 at 10:27




          @simpleguy check my updated answer
          – Raphael at Digital Pianism
          Mar 13 '17 at 10:27












          @RapahelAtDigitalPianism it still not showing, and now there are two checkboxes for massAction
          – simple guy
          Mar 13 '17 at 11:43




          @RapahelAtDigitalPianism it still not showing, and now there are two checkboxes for massAction
          – simple guy
          Mar 13 '17 at 11:43












          is there a way to add the mass action not via xml?
          – simple guy
          Mar 14 '17 at 2:14




          is there a way to add the mass action not via xml?
          – simple guy
          Mar 14 '17 at 2:14












          @simpleguy yes see my edited answer
          – Raphael at Digital Pianism
          Mar 14 '17 at 7:56




          @simpleguy yes see my edited answer
          – Raphael at Digital Pianism
          Mar 14 '17 at 7:56


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f164035%2fmass-action-in-custom-grid-block-magento-2-not-showing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          An IMO inspired problem

          Management

          Investment