I want to create an admin grid which is editable. The problem is that the id column of this grid will be a non auto increment value. Is this possible to implement?
Can any one suggest tutorials or articles related to this?
UPDATE: I'm using a collection which is gained by joining the magento attribute collection with my custom table. Butin the provided code below it contains only product attribute collection.
IDcolumn will contain theattribute_id
Grid.php
<?php
class BalanceAP21Connector_ProductSync_Block_Adminhtml_Attributemapping_Edit_Tab_Attribute
extends Mage_Adminhtml_Block_Widget_Grid
{
/**
* Constructor, ensures pagination is hidden
*/
public function _construct()
{
$this->setId('attribute_edit');
$this->setUseAjax(true);
$this->setDefaultSort('attribute_id');
$this->setPagerVisibility(true);
$this->setSaveParametersInSession(true);
parent::_construct();
}
/**
* Prepare grid collection object. Collection object populated
* based on Apparel 21 module settings in admin configuration section.
*/
public function _prepareCollection()
{
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection->addFieldToFilter('frontend_label', array('notnull' => true));
//echo $collection->getSelectSql();exit;
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}
/**
* Prepare columns for the grid
*/
public function _prepareColumns()
{
$helper = Mage::helper('productsync');
$this->addColumn('attribute_id', array(
'header' => $helper->__('ID'),
'index' => 'attribute_id'
));
$this->addColumn(
'frontend_label',
array(
'header' => $helper->__('Reference Type Name'),
'index' => 'frontend_label'
)
);
$this->addColumn(
'attribute_ids',
array(
'header' => $helper->__('Attribute'),
'width' => '1',
'type' => 'options',
'index' => 'attribute_ids',
'editable' => true,
'options' => Mage::getModel('productsync/attributemapping_system_config_source_attributes')
->toOptionArray(),
'renderer' => 'productsync/adminhtml_attributemapping_widget_grid_column_renderer_options',
)
);
$this->addColumn(
'note_code',
array(
'header' => $helper->__('AP21 note code'),
'index' => 'note_code',
'type' => 'input'
)
);
$this->addColumn(
'note_regexp',
array(
'header' => $helper->__('Note regexp'),
'index' => 'note_regexp',
'type' => 'input'
)
);
return parent::_prepareColumns();
}
public function getGridUrl()
{
//return $this->getUrl("*/*/edit", array("attribute_id" => $row->getId()));
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
My grid is as below. enter image description here
-
good question. +1 for that. Please add more details to the question ? Are you loading a real collection from database in grid ? If yes provide more details of that. If possible, show us your grid fileRajeev K Tomy– Rajeev K Tomy2015年02月19日 01:14:47 +00:00Commented Feb 19, 2015 at 1:14
-
Please any suggestions would be really appreciateSukeshini– Sukeshini2015年02月19日 01:14:56 +00:00Commented Feb 19, 2015 at 1:14
-
Thanks a lot. I edited the question. The collection is not from a real physical table.Sukeshini– Sukeshini2015年02月19日 01:17:43 +00:00Commented Feb 19, 2015 at 1:17
-
if that is the case, please show us the collection that you are using in your grid pageRajeev K Tomy– Rajeev K Tomy2015年02月19日 01:19:26 +00:00Commented Feb 19, 2015 at 1:19
-
Updated the question againSukeshini– Sukeshini2015年02月19日 01:22:32 +00:00Commented Feb 19, 2015 at 1:22
1 Answer 1
To add an edit action and pass some value along with that action, you can use the below code
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array(
'store'=>$this->getRequest()->getParam('store'),
'id'=>$row->getId())
);
}
This will attach a row url to js event handlers and thus when you click on a grid item, it will trigger editAction in your controller file. You can get those parameters like this.
<?php
class [Namespace]_[Module]_[Some]Controller extends Mage_Adminhtml_Controller_Action
{
public function editAction()
{
$id = (int) $this->getRequest()->getParam('id');
}
}
-
Thanks for the response, But I'm not using an action column. There's a save button in the grid container, and wanna save all the modifications when the user click that buttonSukeshini– Sukeshini2015年02月19日 07:09:14 +00:00Commented Feb 19, 2015 at 7:09
-
I didnt get you. You said you want to know how should pass attrbute id when a row is edited ?
getRowUrlis used to do that. you dont want to add anyactioncolumn here. Just add this, then you click on any row, it will triggereditActionin your controllersRajeev K Tomy– Rajeev K Tomy2015年02月19日 07:37:59 +00:00Commented Feb 19, 2015 at 7:37 -
Even if this looks like a grid, actually a form container holds it. So There's only one button to submit the form. I'm not going to submit each rowSukeshini– Sukeshini2015年02月19日 07:44:48 +00:00Commented Feb 19, 2015 at 7:44
-
Im sorry. then what is actaully you are trying to save here.. I mean from the grid page ? and you dont have an edit page here, to edit each of the row ?Rajeev K Tomy– Rajeev K Tomy2015年02月19日 07:47:06 +00:00Commented Feb 19, 2015 at 7:47
-
Edit can be done in the grid it self, you don't need to redirect to any edit page. Please check the image I have attached. I think that will give you a clear understandingSukeshini– Sukeshini2015年02月19日 07:55:52 +00:00Commented Feb 19, 2015 at 7:55