I am very confuse How to Update the Editable Grid Data using Mass action.
I tried but it will got only Id in post. any one done this before then please guide me.
Please See the below Image If any one know the answer then let me know.
ce-1.9.0.1gridgrid-serlizationmagento-1.8
I am very confuse How to Update the Editable Grid Data using Mass action.
I tried but it will got only Id in post. any one done this before then please guide me.
Please See the below Image If any one know the answer then let me know.
I think the problem comes from the layout file (at least it was for me some time ago, that's why I asked for the layout code). Mainly this:
<adminhtml_swatchrequest_grid>
<block type="baddass_swatchrequest/adminhtml_swatchrequest_grid" name="ajax_grid" output="toHtml"/>
</adminhtml_swatchrequest_grid>
The block should have a wrapper around it.
<adminhtml_swatchrequest_grid>
<block type="core/text_list" name="root" output="toHtml">
<block type="baddass_swatchrequest/adminhtml_swatchrequest_grid" name="ajax_grid"/>
</block>
</adminhtml_swatchrequest_grid>
This allows Magento to add the block that contains the form_key to the response of the ajax request. The form_key
is required for all POST requests. That's why the mass action didn't work after filtering, because you didn't have anymore the form_key
.
You can also put back $this->setSaveParamatersInSession(true)
(I realized is not relevant. I wanted to refer to $this->setUseAjax(true);
. Stupid mistake. Sorry.)
Following I give some example which I have done before. Mine contains one edit form and one ajax grid, but with this logic, you can add any number of tabs and grids in this form. File structuire:
1./app/code/local/Ssd/Experts/Block/Adminhtml/Experts.php
/**
* Experts management Grid container, row click opents expert edit page
*/
class Ssd_Experts_Block_Adminhtml_Experts extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function _construct()
{
$this->_controller = 'adminhtml_experts';
$this->_blockGroup = 'experts';
$this->_headerText = Mage::helper('experts')->__('Manage experts');
$this->_addButtonLabel = Mage::helper('brands')->__('Add Expert');
parent::_construct();
}
}
2./app/code/local/Ssd/Experts/Block/Adminhtml/Experts/Grid.php
class Ssd_Experts_Block_Adminhtml_Experts_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('expertsGrid');
$this->setDefaultSort('name');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('experts/experts')->getCollection()->addCategoryData();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('expert_name', array(
'header' => Mage::helper('experts')->__('Name'),
'align' => 'left',
'index' => 'expert_name',
'width' => '250',
));
/**
* another columns here
*/
return parent::_prepareColumns();
}
}
3./app/code/local/Ssd/Experts/Block/Adminhtml/Experts/Edit.php
/**
* Expert edit form container
*/
class Ssd_Experts_Block_Adminhtml_Experts_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function __construct()
{
parent::__construct();
$this->_objectId = 'id';
$this->_blockGroup = "experts";
$this->_controller = "adminhtml_experts";
$this->updateButton('delete', 'label', Mage::helper('experts')->__('Delete Expert'));
$this->updateButton('save', 'label', Mage::helper('experts')->__('Save Expert'));
}
}
4./app/code/local/Ssd/Experts/Block/Adminhtml/Experts/Edit/Tabs.php
class Ssd_Experts_Block_Adminhtml_Experts_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
public function __construct()
{
parent::__construct();
$this->setId('experts_tab');
$this->setDestElementId('edit_form');
}
protected function _beforeToHtml()
{
//edit form tab
$this->addTab('expert_form_edit', array(
'label' => Mage::helper('brands')->__('Edit Expert'),
'title' => Mage::helper('brands')->__('Edit Expert'),
'content' => $this->getLayout()->createBlock('experts/adminhtml_experts_edit_tab_form')->toHtml(),
'active' => true
));
if (Mage::registry('experts_data') && Mage::registry('experts_data')->getId()) {
//grid tab
$this->addTab('expert_advices', array(
'label' => Mage::helper('experts')->__('Expert Advices'),
'title' => Mage::helper('experts')->__('Expert Advices'),
'content' => $this->getLayout()->createBlock('experts/adminhtml_experts_edit_tab_advices_grid')->toHtml(),
));
}
//also you can add another grid tab
/*$this->addTab('expert_advices', array(
'label' => Mage::helper('experts')->__('Another Grid'),
'title' => Mage::helper('experts')->__('Another Grid'),
'content' => $this->getLayout()->createBlock('experts/adminhtml_experts_edit_tab_another_grid')->toHtml(),
));*/
return parent::_beforeToHtml();
}
}
5./app/code/local/Ssd/Experts/Block/Adminhtml/Experts/Edit/Form.php
class Ssd_Experts_Block_Adminhtml_Experts_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data',
));
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
6./app/code/local/Ssd/Experts/Block/Adminhtml/Experts/Edit/Tab/Form.php
class Ssd_Experts_Block_Adminhtml_Experts_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('personal_information', array(
'legend' => Mage::helper('experts')->__('Personal Information'),
'class' => 'fieldset-wide',
));
$fieldset->addField('expert_name', 'text', array(
'label' => Mage::helper('experts')->__('Expert Name'),
'required' => true,
'name' => 'expert_name',
));
/**
* another elements here
* this is typical edit form
*/
return parent::_prepareForm();
}
}
7./app/code/local/Ssd/Experts/Block/Adminhtml/Experts/Edit/Tab/Advices/Grid.php
/**
* this is typical grid, but it also impelents tab interface
*/
class Ssd_Experts_Block_Adminhtml_Experts_Edit_Tab_Advices_Grid extends Mage_Adminhtml_Block_Widget_Grid
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function _construct()
{
parent::_construct();
$this->setId('expert_advice_grid');
$this->setDefaultSort('page_title');
$this->setDefaultDir('ASC');
//enable ajax grid
$this->setUseAjax(true);
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('experts/advices')
->getCollection()
->addExpertData()
->addFieldToFilter('main_table.expert_id', Mage::app()->getRequest()->getParam('id'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('advice_title', array(
'header' => Mage::helper('experts')->__('Title'),
'align' => 'left',
'index' => 'advice_title',
));
/**
* add another columns here
*/
return parent::_prepareColumns();
}
//this method is reuired if you want ajax grid
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current' => true));
}
public function canShowTab()
{
return true;
}
public function isHidden()
{
return false;
}
public function getTabLabel()
{
return $this->__('Settings');
}
public function getTabTitle()
{
return $this->__('Expert Advices');
}
}
8./app/code/local/Ssd/Experts/Block/Adminhtml/Experts/Edit/Tab/Another/Grid.php
class Ssd_Experts_Block_Adminhtml_Experts_Edit_Tab_Another_Grid extends Mage_Adminhtml_Block_Widget_Grid
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function _construct()
{
parent::_construct();
$this->setId('expert_another_grid');
//enable ajax grid
$this->setUseAjax(true);
}
protected function _prepareCollection()
{
/**
* prepare collection what you want
*/
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
/**
* add another columns here
*/
return parent::_prepareColumns();
}
//this method is reuired if you want ajax grid
public function getGridUrl()
{
return $this->getUrl('*/*/anothergrid', array('_current' => true));
}
/**
* implement tab interface methods
*/
}
9./app/code/local/Ssd/Experts/controllers/Adminhtml/ExpertsController.php
class Ssd_Experts_Adminhtml_ExpertsController extends Mage_Adminhtml_Controller_Action
{
//this is ajax grid request action
public function gridAction()
{
echo $this->getLayout()->createBlock('experts/adminhtml_experts_edit_tab_advices_grid')->toHtml();
}
public function editAction()
{
$expertModel = Mage::getModel('experts/experts')->load($this->getRequest()->getParam('id'));
if ($expertModel->getId()) {
Mage::register('experts_data', $expertModel);
$this->loadLayout();
//attention here, what blocks are creating, left is tab, content is edit container
$this->_addLeft($this->getLayout()->createBlock('experts/adminhtml_experts_edit_tabs'));
$this->_addContent($this->getLayout()->createBlock('experts/adminhtml_experts_edit'));
$this->renderLayout();
} else {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('experts')->__('Expert does not exist'));
$this->_redirect('*/*/');
}
}
/**
* another actions here: index, delete, mass....
*/
}
I hope you can understand file structure using class names. some codes are cutted out. My experts edit form contains edit form container, tabs, end each tab content is can be form controls, grid or any content what you want. Additional comments are in the code. Hope this example helps you.
Best Answer
I cannot give you the direct answer but I definitely know the way.
For every admin grid magento creates javascript object
varienGridMassaction
. It is defined in\js\mage\adminhtml\grid.js
.During selecting checkboxes in grid,
varienGridMassaction
object saves ids of selected rows.When you select mass action type and press Submit button you are not submitting form in normal meaning of this word. This button runs
varienGridMassaction::apply()
, which gets all selected ids and sends them with mass action type to the server.So you cannot simply add
input
s and make them be transferred with usual mass action data.Possible solutions:
varienGridMassaction
to send more data during submit.