Magento 2.2.5: Idea about delete “Banner_Slide”
i'm doing "Banner Slider" and looking for how to delete column in banner_slide
. Its hard to explain. So just look in my example:
So this is what i've done til now. A banner which contain 3 slide.
What i want is when i click in that checkbox to turn off the choose, it will count and render through HTML and then when i click Save Banner
or Save and Continue Edit
, it will delete columns in banner_slide
table in Mysql that have checkbox turning off.
So i'm following the catalog_category_products
in magento 2. And what they do is look like this:
Like you can see, it render into HTML like i said.
And when i click on Save Banner
button, it will run into Controller/../Save.php
and save data to banner_slide
table in Mysql.
So here is the Save.php:
C:xampphtdocsmagentoappcodeAhtBannerSliderControllerAdminhtmlManageSave.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 20/07/2018
* Time: 4:15 CH
*/
namespace AhtBannerSliderControllerAdminhtmlManage;
use MagentoBackendAppActionContext;
use AhtBannerSliderModelBannerFactory;
use AhtBannerSliderModelBannerSlideFactory;
class Save extends MagentoFrameworkAppActionAction
{
protected $bannerFactory;
protected $bannerSlideFactory;
public function __construct(
Context $context,
BannerFactory $bannerFactory,
BannerSlideFactory $bannerSlideFactory
) {
$this->bannerFactory = $bannerFactory;
$this->bannerSlideFactory = $bannerSlideFactory;
parent::__construct($context);
}
/**
* Save action
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
{
$data = $this->getRequest()->getPostValue();
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
//
if ($data) {
try{
$id = $this->getRequest()->getParam('id');
$banner = $this->bannerFactory->create();
if(isset($data['banner_slide'])){
// lấy chuỗi json banner_slide được truyền vào từ form HTML.
$slide = json_decode($data['banner_slide'], true);
foreach($slide as $key => $value){
$bannerSlide = $this->bannerSlideFactory->create();
// check xem banner_slider này đã tồn tại hay chưa, nếu tồn tại thì không insert vào db.
$check = $bannerSlide->getCollection()
->addFieldToFilter('banner_id',$id)
->addFieldToFilter('slide_id',$key)
->getSize();
if($check = 0){
$bannerSlide->setBannerId($id);
$bannerSlide->setSlideId($key);
$bannerSlide->setPosition($value);
$bannerSlide->save();
}
}
}
if($id){
$banner->load($id);
$data['id'] = $id;
}
$banner->setData($data);
$banner->save();
if ($id) {
$this->messageManager->addSuccessMessage(__('Update Banner Successfully.'));
} else {
$this->messageManager->addSuccessMessage(__('Add Banner Successfully.'));
}
// check for Save and Continue Edit Button
if ($this->getRequest()->getParam('back')) {
return $resultRedirect->setPath('*/*/detail', ['id' => $banner->getId(), '_current' => true]);
} else {
$resultRedirect->setPath('*/*/');
}
return $resultRedirect;
}
catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
}
}
}
Here is my banner_slide table:
I can save into the database through foreach loop successfully the banner_slide
which "checkbox" turning on, but i dont know how to do that with banner_slide
which turning off. So i need an idea on how to do that...
Thanks for reading. Have a good day :)
EDIT 1:
So i've found 2 way to do this:
- Delete all the record in table and then insert again.
- Select all the record in table and compare with the json banner_slide, and what doesn't have in json will be delete.
But what if i have 1000 record in the table? So these 2 way are not really good.
magento2 delete banner-slider
add a comment |
i'm doing "Banner Slider" and looking for how to delete column in banner_slide
. Its hard to explain. So just look in my example:
So this is what i've done til now. A banner which contain 3 slide.
What i want is when i click in that checkbox to turn off the choose, it will count and render through HTML and then when i click Save Banner
or Save and Continue Edit
, it will delete columns in banner_slide
table in Mysql that have checkbox turning off.
So i'm following the catalog_category_products
in magento 2. And what they do is look like this:
Like you can see, it render into HTML like i said.
And when i click on Save Banner
button, it will run into Controller/../Save.php
and save data to banner_slide
table in Mysql.
So here is the Save.php:
C:xampphtdocsmagentoappcodeAhtBannerSliderControllerAdminhtmlManageSave.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 20/07/2018
* Time: 4:15 CH
*/
namespace AhtBannerSliderControllerAdminhtmlManage;
use MagentoBackendAppActionContext;
use AhtBannerSliderModelBannerFactory;
use AhtBannerSliderModelBannerSlideFactory;
class Save extends MagentoFrameworkAppActionAction
{
protected $bannerFactory;
protected $bannerSlideFactory;
public function __construct(
Context $context,
BannerFactory $bannerFactory,
BannerSlideFactory $bannerSlideFactory
) {
$this->bannerFactory = $bannerFactory;
$this->bannerSlideFactory = $bannerSlideFactory;
parent::__construct($context);
}
/**
* Save action
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
{
$data = $this->getRequest()->getPostValue();
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
//
if ($data) {
try{
$id = $this->getRequest()->getParam('id');
$banner = $this->bannerFactory->create();
if(isset($data['banner_slide'])){
// lấy chuỗi json banner_slide được truyền vào từ form HTML.
$slide = json_decode($data['banner_slide'], true);
foreach($slide as $key => $value){
$bannerSlide = $this->bannerSlideFactory->create();
// check xem banner_slider này đã tồn tại hay chưa, nếu tồn tại thì không insert vào db.
$check = $bannerSlide->getCollection()
->addFieldToFilter('banner_id',$id)
->addFieldToFilter('slide_id',$key)
->getSize();
if($check = 0){
$bannerSlide->setBannerId($id);
$bannerSlide->setSlideId($key);
$bannerSlide->setPosition($value);
$bannerSlide->save();
}
}
}
if($id){
$banner->load($id);
$data['id'] = $id;
}
$banner->setData($data);
$banner->save();
if ($id) {
$this->messageManager->addSuccessMessage(__('Update Banner Successfully.'));
} else {
$this->messageManager->addSuccessMessage(__('Add Banner Successfully.'));
}
// check for Save and Continue Edit Button
if ($this->getRequest()->getParam('back')) {
return $resultRedirect->setPath('*/*/detail', ['id' => $banner->getId(), '_current' => true]);
} else {
$resultRedirect->setPath('*/*/');
}
return $resultRedirect;
}
catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
}
}
}
Here is my banner_slide table:
I can save into the database through foreach loop successfully the banner_slide
which "checkbox" turning on, but i dont know how to do that with banner_slide
which turning off. So i need an idea on how to do that...
Thanks for reading. Have a good day :)
EDIT 1:
So i've found 2 way to do this:
- Delete all the record in table and then insert again.
- Select all the record in table and compare with the json banner_slide, and what doesn't have in json will be delete.
But what if i have 1000 record in the table? So these 2 way are not really good.
magento2 delete banner-slider
add a comment |
i'm doing "Banner Slider" and looking for how to delete column in banner_slide
. Its hard to explain. So just look in my example:
So this is what i've done til now. A banner which contain 3 slide.
What i want is when i click in that checkbox to turn off the choose, it will count and render through HTML and then when i click Save Banner
or Save and Continue Edit
, it will delete columns in banner_slide
table in Mysql that have checkbox turning off.
So i'm following the catalog_category_products
in magento 2. And what they do is look like this:
Like you can see, it render into HTML like i said.
And when i click on Save Banner
button, it will run into Controller/../Save.php
and save data to banner_slide
table in Mysql.
So here is the Save.php:
C:xampphtdocsmagentoappcodeAhtBannerSliderControllerAdminhtmlManageSave.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 20/07/2018
* Time: 4:15 CH
*/
namespace AhtBannerSliderControllerAdminhtmlManage;
use MagentoBackendAppActionContext;
use AhtBannerSliderModelBannerFactory;
use AhtBannerSliderModelBannerSlideFactory;
class Save extends MagentoFrameworkAppActionAction
{
protected $bannerFactory;
protected $bannerSlideFactory;
public function __construct(
Context $context,
BannerFactory $bannerFactory,
BannerSlideFactory $bannerSlideFactory
) {
$this->bannerFactory = $bannerFactory;
$this->bannerSlideFactory = $bannerSlideFactory;
parent::__construct($context);
}
/**
* Save action
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
{
$data = $this->getRequest()->getPostValue();
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
//
if ($data) {
try{
$id = $this->getRequest()->getParam('id');
$banner = $this->bannerFactory->create();
if(isset($data['banner_slide'])){
// lấy chuỗi json banner_slide được truyền vào từ form HTML.
$slide = json_decode($data['banner_slide'], true);
foreach($slide as $key => $value){
$bannerSlide = $this->bannerSlideFactory->create();
// check xem banner_slider này đã tồn tại hay chưa, nếu tồn tại thì không insert vào db.
$check = $bannerSlide->getCollection()
->addFieldToFilter('banner_id',$id)
->addFieldToFilter('slide_id',$key)
->getSize();
if($check = 0){
$bannerSlide->setBannerId($id);
$bannerSlide->setSlideId($key);
$bannerSlide->setPosition($value);
$bannerSlide->save();
}
}
}
if($id){
$banner->load($id);
$data['id'] = $id;
}
$banner->setData($data);
$banner->save();
if ($id) {
$this->messageManager->addSuccessMessage(__('Update Banner Successfully.'));
} else {
$this->messageManager->addSuccessMessage(__('Add Banner Successfully.'));
}
// check for Save and Continue Edit Button
if ($this->getRequest()->getParam('back')) {
return $resultRedirect->setPath('*/*/detail', ['id' => $banner->getId(), '_current' => true]);
} else {
$resultRedirect->setPath('*/*/');
}
return $resultRedirect;
}
catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
}
}
}
Here is my banner_slide table:
I can save into the database through foreach loop successfully the banner_slide
which "checkbox" turning on, but i dont know how to do that with banner_slide
which turning off. So i need an idea on how to do that...
Thanks for reading. Have a good day :)
EDIT 1:
So i've found 2 way to do this:
- Delete all the record in table and then insert again.
- Select all the record in table and compare with the json banner_slide, and what doesn't have in json will be delete.
But what if i have 1000 record in the table? So these 2 way are not really good.
magento2 delete banner-slider
i'm doing "Banner Slider" and looking for how to delete column in banner_slide
. Its hard to explain. So just look in my example:
So this is what i've done til now. A banner which contain 3 slide.
What i want is when i click in that checkbox to turn off the choose, it will count and render through HTML and then when i click Save Banner
or Save and Continue Edit
, it will delete columns in banner_slide
table in Mysql that have checkbox turning off.
So i'm following the catalog_category_products
in magento 2. And what they do is look like this:
Like you can see, it render into HTML like i said.
And when i click on Save Banner
button, it will run into Controller/../Save.php
and save data to banner_slide
table in Mysql.
So here is the Save.php:
C:xampphtdocsmagentoappcodeAhtBannerSliderControllerAdminhtmlManageSave.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 20/07/2018
* Time: 4:15 CH
*/
namespace AhtBannerSliderControllerAdminhtmlManage;
use MagentoBackendAppActionContext;
use AhtBannerSliderModelBannerFactory;
use AhtBannerSliderModelBannerSlideFactory;
class Save extends MagentoFrameworkAppActionAction
{
protected $bannerFactory;
protected $bannerSlideFactory;
public function __construct(
Context $context,
BannerFactory $bannerFactory,
BannerSlideFactory $bannerSlideFactory
) {
$this->bannerFactory = $bannerFactory;
$this->bannerSlideFactory = $bannerSlideFactory;
parent::__construct($context);
}
/**
* Save action
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
{
$data = $this->getRequest()->getPostValue();
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
//
if ($data) {
try{
$id = $this->getRequest()->getParam('id');
$banner = $this->bannerFactory->create();
if(isset($data['banner_slide'])){
// lấy chuỗi json banner_slide được truyền vào từ form HTML.
$slide = json_decode($data['banner_slide'], true);
foreach($slide as $key => $value){
$bannerSlide = $this->bannerSlideFactory->create();
// check xem banner_slider này đã tồn tại hay chưa, nếu tồn tại thì không insert vào db.
$check = $bannerSlide->getCollection()
->addFieldToFilter('banner_id',$id)
->addFieldToFilter('slide_id',$key)
->getSize();
if($check = 0){
$bannerSlide->setBannerId($id);
$bannerSlide->setSlideId($key);
$bannerSlide->setPosition($value);
$bannerSlide->save();
}
}
}
if($id){
$banner->load($id);
$data['id'] = $id;
}
$banner->setData($data);
$banner->save();
if ($id) {
$this->messageManager->addSuccessMessage(__('Update Banner Successfully.'));
} else {
$this->messageManager->addSuccessMessage(__('Add Banner Successfully.'));
}
// check for Save and Continue Edit Button
if ($this->getRequest()->getParam('back')) {
return $resultRedirect->setPath('*/*/detail', ['id' => $banner->getId(), '_current' => true]);
} else {
$resultRedirect->setPath('*/*/');
}
return $resultRedirect;
}
catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
}
}
}
Here is my banner_slide table:
I can save into the database through foreach loop successfully the banner_slide
which "checkbox" turning on, but i dont know how to do that with banner_slide
which turning off. So i need an idea on how to do that...
Thanks for reading. Have a good day :)
EDIT 1:
So i've found 2 way to do this:
- Delete all the record in table and then insert again.
- Select all the record in table and compare with the json banner_slide, and what doesn't have in json will be delete.
But what if i have 1000 record in the table? So these 2 way are not really good.
magento2 delete banner-slider
magento2 delete banner-slider
edited 6 mins ago
Teja Bhagavan Kollepara
3,01241949
3,01241949
asked Aug 10 '18 at 14:50
fudufudu
42311
42311
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Add the below code to your Grid.php:
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('id');
$this->getMassactionBlock()->addItem(
'delete',
array(
'label' => __('Delete'),
'url' => $this->getUrl('banner/*/massDelete'),
'confirm' => __('Are you sure?')
)
);
return $this;
}
Also create Delete.php controller and the below code under your module like below path:
app/code/Vendor/Banner/Controller/Adminhtml/Banner/Delete.php
Code for Delete.php:
<?php
namespace VendorBannerControllerAdminhtmlBanner;
class MassDelete extends MagentoBackendAppAction
{
/**
* @var MagentoFrameworkViewResultPageFactory
*/
public function execute()
{
$ids = $this->getRequest()->getParam('id');
if (!is_array($ids) || empty($ids)) {
$this->messageManager->addError(__('Please select product(s).'));
} else {
try {
foreach ($ids as $id) {
$row = $this->_objectManager->get('VendorBannerModelBanner')->load($id);
$row->delete();
}
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', count($ids))
);
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
$this->_redirect('*/*/');
}
}
You need to change the Vendor and Module name according to your requirement.
hold up, so where exactly this massActionDelete should render in HTML?
– fudu
Aug 10 '18 at 15:25
if it render a Delete Action button, so i dont need it, because what i want is click the checkbox and then click "Save" button .
– fudu
Aug 10 '18 at 15:26
Just above your grid.
– Sukumar Gorai
Aug 10 '18 at 15:26
Mass action will show as a dropdown. from there you can select delete option and submit then all the selected banners will be deleted.
– Sukumar Gorai
Aug 10 '18 at 15:27
Yes i can see that, but that's not what i'm looking for .. @@ The goal here is when i click "save" , then it will delete what doesn't turn on in the checkbox.
– fudu
Aug 10 '18 at 15:46
|
show 4 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f237998%2fmagento-2-2-5-idea-about-delete-banner-slide%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
Add the below code to your Grid.php:
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('id');
$this->getMassactionBlock()->addItem(
'delete',
array(
'label' => __('Delete'),
'url' => $this->getUrl('banner/*/massDelete'),
'confirm' => __('Are you sure?')
)
);
return $this;
}
Also create Delete.php controller and the below code under your module like below path:
app/code/Vendor/Banner/Controller/Adminhtml/Banner/Delete.php
Code for Delete.php:
<?php
namespace VendorBannerControllerAdminhtmlBanner;
class MassDelete extends MagentoBackendAppAction
{
/**
* @var MagentoFrameworkViewResultPageFactory
*/
public function execute()
{
$ids = $this->getRequest()->getParam('id');
if (!is_array($ids) || empty($ids)) {
$this->messageManager->addError(__('Please select product(s).'));
} else {
try {
foreach ($ids as $id) {
$row = $this->_objectManager->get('VendorBannerModelBanner')->load($id);
$row->delete();
}
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', count($ids))
);
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
$this->_redirect('*/*/');
}
}
You need to change the Vendor and Module name according to your requirement.
hold up, so where exactly this massActionDelete should render in HTML?
– fudu
Aug 10 '18 at 15:25
if it render a Delete Action button, so i dont need it, because what i want is click the checkbox and then click "Save" button .
– fudu
Aug 10 '18 at 15:26
Just above your grid.
– Sukumar Gorai
Aug 10 '18 at 15:26
Mass action will show as a dropdown. from there you can select delete option and submit then all the selected banners will be deleted.
– Sukumar Gorai
Aug 10 '18 at 15:27
Yes i can see that, but that's not what i'm looking for .. @@ The goal here is when i click "save" , then it will delete what doesn't turn on in the checkbox.
– fudu
Aug 10 '18 at 15:46
|
show 4 more comments
Add the below code to your Grid.php:
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('id');
$this->getMassactionBlock()->addItem(
'delete',
array(
'label' => __('Delete'),
'url' => $this->getUrl('banner/*/massDelete'),
'confirm' => __('Are you sure?')
)
);
return $this;
}
Also create Delete.php controller and the below code under your module like below path:
app/code/Vendor/Banner/Controller/Adminhtml/Banner/Delete.php
Code for Delete.php:
<?php
namespace VendorBannerControllerAdminhtmlBanner;
class MassDelete extends MagentoBackendAppAction
{
/**
* @var MagentoFrameworkViewResultPageFactory
*/
public function execute()
{
$ids = $this->getRequest()->getParam('id');
if (!is_array($ids) || empty($ids)) {
$this->messageManager->addError(__('Please select product(s).'));
} else {
try {
foreach ($ids as $id) {
$row = $this->_objectManager->get('VendorBannerModelBanner')->load($id);
$row->delete();
}
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', count($ids))
);
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
$this->_redirect('*/*/');
}
}
You need to change the Vendor and Module name according to your requirement.
hold up, so where exactly this massActionDelete should render in HTML?
– fudu
Aug 10 '18 at 15:25
if it render a Delete Action button, so i dont need it, because what i want is click the checkbox and then click "Save" button .
– fudu
Aug 10 '18 at 15:26
Just above your grid.
– Sukumar Gorai
Aug 10 '18 at 15:26
Mass action will show as a dropdown. from there you can select delete option and submit then all the selected banners will be deleted.
– Sukumar Gorai
Aug 10 '18 at 15:27
Yes i can see that, but that's not what i'm looking for .. @@ The goal here is when i click "save" , then it will delete what doesn't turn on in the checkbox.
– fudu
Aug 10 '18 at 15:46
|
show 4 more comments
Add the below code to your Grid.php:
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('id');
$this->getMassactionBlock()->addItem(
'delete',
array(
'label' => __('Delete'),
'url' => $this->getUrl('banner/*/massDelete'),
'confirm' => __('Are you sure?')
)
);
return $this;
}
Also create Delete.php controller and the below code under your module like below path:
app/code/Vendor/Banner/Controller/Adminhtml/Banner/Delete.php
Code for Delete.php:
<?php
namespace VendorBannerControllerAdminhtmlBanner;
class MassDelete extends MagentoBackendAppAction
{
/**
* @var MagentoFrameworkViewResultPageFactory
*/
public function execute()
{
$ids = $this->getRequest()->getParam('id');
if (!is_array($ids) || empty($ids)) {
$this->messageManager->addError(__('Please select product(s).'));
} else {
try {
foreach ($ids as $id) {
$row = $this->_objectManager->get('VendorBannerModelBanner')->load($id);
$row->delete();
}
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', count($ids))
);
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
$this->_redirect('*/*/');
}
}
You need to change the Vendor and Module name according to your requirement.
Add the below code to your Grid.php:
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('id');
$this->getMassactionBlock()->addItem(
'delete',
array(
'label' => __('Delete'),
'url' => $this->getUrl('banner/*/massDelete'),
'confirm' => __('Are you sure?')
)
);
return $this;
}
Also create Delete.php controller and the below code under your module like below path:
app/code/Vendor/Banner/Controller/Adminhtml/Banner/Delete.php
Code for Delete.php:
<?php
namespace VendorBannerControllerAdminhtmlBanner;
class MassDelete extends MagentoBackendAppAction
{
/**
* @var MagentoFrameworkViewResultPageFactory
*/
public function execute()
{
$ids = $this->getRequest()->getParam('id');
if (!is_array($ids) || empty($ids)) {
$this->messageManager->addError(__('Please select product(s).'));
} else {
try {
foreach ($ids as $id) {
$row = $this->_objectManager->get('VendorBannerModelBanner')->load($id);
$row->delete();
}
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', count($ids))
);
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
$this->_redirect('*/*/');
}
}
You need to change the Vendor and Module name according to your requirement.
answered Aug 10 '18 at 15:14
Sukumar GoraiSukumar Gorai
6,9303729
6,9303729
hold up, so where exactly this massActionDelete should render in HTML?
– fudu
Aug 10 '18 at 15:25
if it render a Delete Action button, so i dont need it, because what i want is click the checkbox and then click "Save" button .
– fudu
Aug 10 '18 at 15:26
Just above your grid.
– Sukumar Gorai
Aug 10 '18 at 15:26
Mass action will show as a dropdown. from there you can select delete option and submit then all the selected banners will be deleted.
– Sukumar Gorai
Aug 10 '18 at 15:27
Yes i can see that, but that's not what i'm looking for .. @@ The goal here is when i click "save" , then it will delete what doesn't turn on in the checkbox.
– fudu
Aug 10 '18 at 15:46
|
show 4 more comments
hold up, so where exactly this massActionDelete should render in HTML?
– fudu
Aug 10 '18 at 15:25
if it render a Delete Action button, so i dont need it, because what i want is click the checkbox and then click "Save" button .
– fudu
Aug 10 '18 at 15:26
Just above your grid.
– Sukumar Gorai
Aug 10 '18 at 15:26
Mass action will show as a dropdown. from there you can select delete option and submit then all the selected banners will be deleted.
– Sukumar Gorai
Aug 10 '18 at 15:27
Yes i can see that, but that's not what i'm looking for .. @@ The goal here is when i click "save" , then it will delete what doesn't turn on in the checkbox.
– fudu
Aug 10 '18 at 15:46
hold up, so where exactly this massActionDelete should render in HTML?
– fudu
Aug 10 '18 at 15:25
hold up, so where exactly this massActionDelete should render in HTML?
– fudu
Aug 10 '18 at 15:25
if it render a Delete Action button, so i dont need it, because what i want is click the checkbox and then click "Save" button .
– fudu
Aug 10 '18 at 15:26
if it render a Delete Action button, so i dont need it, because what i want is click the checkbox and then click "Save" button .
– fudu
Aug 10 '18 at 15:26
Just above your grid.
– Sukumar Gorai
Aug 10 '18 at 15:26
Just above your grid.
– Sukumar Gorai
Aug 10 '18 at 15:26
Mass action will show as a dropdown. from there you can select delete option and submit then all the selected banners will be deleted.
– Sukumar Gorai
Aug 10 '18 at 15:27
Mass action will show as a dropdown. from there you can select delete option and submit then all the selected banners will be deleted.
– Sukumar Gorai
Aug 10 '18 at 15:27
Yes i can see that, but that's not what i'm looking for .. @@ The goal here is when i click "save" , then it will delete what doesn't turn on in the checkbox.
– fudu
Aug 10 '18 at 15:46
Yes i can see that, but that's not what i'm looking for .. @@ The goal here is when i click "save" , then it will delete what doesn't turn on in the checkbox.
– fudu
Aug 10 '18 at 15:46
|
show 4 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f237998%2fmagento-2-2-5-idea-about-delete-banner-slide%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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