Add onclick method on checkbox on grid in sales order? - magento

I have added a custom column at sales_order_grid table and add this code at _prepareColumns() functions at grid.php and this checkbox is now showing but i cann't add onclick function at this column ,
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'checkbox',
'field_name'=>'exported_',
'values' => array(1,2),//$this->_getExported(),//
'onclick' => $this->getJsObjectName('addRelatedToExport'),
));
I am stuck from 4 days,Help me ,
Thanks in advance.

Include this function in your grid file. Grid.php
protected function _prepareMassaction(){
$this->setMassactionIdField('entity_id'); // code to make the checkbox related with
$this->getMassactionBlock()->setFormFieldName('form_field_name');
$this->getMassactionBlock()->addItem('addRelatedToExport', array(
'label'=> Mage::helper('ModuleName')->__('Add to Export'),
'url' => $this->getUrl('*/*/massRelatedExport')
));
return $this;
}
And then in the same module controller e.g ModuleName/controllers/adminhtml/someController
public function massRelatedExportAction(){
// your code here
}

Related

magento show content according to condition in admin grid

I have developed custom admin module. I have used the usual methods _prepareCollection and _prepareColumns to show the data in Grid.
protected function _prepareCollection()
{
$collection = Mage::getModel("wallets/sellerrequest")->getCollection();
$collection->getSelect()
->join( array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.seller_id and ce1.attribute_id = "5"', array('seller_name' => 'value'));
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}
protected function _prepareColumns()
{
$helper = Mage::helper('sellers');
$currency = (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
$this->addColumn('id', array(
'header' => $helper->__('Request No'),
'index' => 'id'
));
$this->addColumn('Requested Amount', array(
'header' => $helper->__('Requested Amount'),
'index' => 'request_amount'
));
$this->addColumn('Seller Name', array(
'header' => $helper->__('Seller Name'),
'index' => 'seller_name',
));
$this->addColumn('Status', array(
'header' => $helper->__('Status'),
'index' => 'status_flag'
));
All the data shows correctly according to the table values. But I want to show the Request Amount column values preceding with $ sign, e.g. $300 etc. Also, I want to show the status flag according to condition. Means if the status flag is 1 then I want to show the value as "Approved", if flag is 2 then "Pending" etc. How should I customize the collection data and show in grid according to my requirement? Help appreciated.
Thanks.
I have answered to a question similar to your requirement
How to properly add a shipping_description column in magento order grid?
Check my answer and try to compare with your problem. In this example there is the solution for our currency problem too.
So check this out.Hope it will be helpful.
Here you should implement Grid Renderer.
Here is complete tutorial for that : http://inchoo.net/magento/how-to-add-custom-renderer-for-a-custom-column-in-magento-grid/
You can customize the value of any colum

Add and show new column in sales_flat_order and show this at order grid in magento

I have added a new column (exported)in sales_flat_order and add at files at this location:
app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->addAttributeToSelect('*')
->joinAttribute('exported','sales/order','sales_flat_order.entity_id',null,'left');
}
protected function _prepareColumns()
{
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'checkbox',
'name' =>'exported',
'value' =>$this->getExported()==1 ? 'true' : 'false',
));
}
after that it showing on order grid in admin site,but it is not showing value and name,
I am new in magento,so please help me ,
stuck from 2 days.
Thanks for Assistance.
The method _prepareCollection() uses sales_flat_order_grid table as asource, thus you have to add the column to sales_flat_order_grid table and update the values of that column from the appropriate column of sales_flat_order table.
In this case, Magento will automatically update this column in sales_flat_order_grid table for future orders.
The better way to display the boolean column is Yes/No renderer. Use the following code for this in _prepareColumns() method
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'options',
'width' => '70px',
'options' => array(
1 => Mage::helper('sales')->__('Yes'),
0 => Mage::helper('sales')->__('No'),
),
));
There are some other useful articles about cutomizing order grid. Check out the links below:
http://inchoo.net/ecommerce/magento/how-to-extend-magento-order-grid/
http://www.ecomdev.org/2010/07/27/adding-order-attribute-to-orders-grid-in-magento-1-4-1.html
http://www.demacmedia.com/magento-commerce/mini-tutorial-adding-column-to-orders-grid-in-magento-backend/
http://www.atwix.com/magento/column-to-orders-grid/

Magento. Why in admin grid the column is displayed always at the end even using addColumnAfter

I created an Observer which adds a field to the newsletter grid in admin like this:
public function AddItemColumnToGrid($observer)
{
...
if ($_type == 'adminhtml/newsletter_subscriber_grid') {
$_block->addColumnAfter('subscriber_name', array(
'header'=> Mage::helper('newsletter')->__('Name'),
'type' => 'text',
'index' => 'subscriber_name',
), 'subscriber_email');
}
...
}
I cannot figure out. But Magento always displays my Subscriber_name field at the end (as the last in the order). ColumnAfter doesn't work. Why ?
I'm overring this:
<events>
<adminhtml_block_html_before>
It's because the sorting happens before you hook into the HTML generation:
Mage_Adminhtml_Block_Widget_Grid:
protected function _beforeToHtml()
{
$this->_prepareGrid(); // <-- sort columns
return parent::_beforeToHtml(); // <-- dispatch event
}
What you could do is sort again after adding the column:
$_block->addColumnAfter('subscriber_name', array(
'header'=> Mage::helper('newsletter')->__('Name'),
'type' => 'text',
'index' => 'subscriber_name',
), 'subscriber_email');
$_block->sortColumnsByOrder();

How to customize the database value in magento customer grid

I created new magento grid for customer module for special purpose.
In that there have a column usertype it have value as 0,1,2.
It will displayed in customer grid page as 0,1,2.
But i need to display if value is,
0 -> Inactive
1 -> Activated
2 -> Baned
How can i dothis?
This is my code grid.php in _prepareColumns() :
$this->addColumn('usertype', array(
'header' => Mage::helper('customer')->__('Usertype'),
'width' => '150',
'index' => 'usertype'
));
If this is possible in magento.
if your greed implements Mage_Adminhtml_Block_Widget_Grid I suggest you to modify
you addColumn call to
$this->addColumn('usertype',
array(
'header'=> Mage::helper('customer')->__('Usertype'),
'width' => '150px',
'index' => 'usertype',
'type' => 'options',
'options' => $values
));
Where $values should be formatted as
array( 'value_id' => 'value_label')
Now you have dropdown created with values.
Then update _prepareCollection() function and add attribute values to customer grid collection
$collection->joinAttribute('usertype', 'customer/usertype', 'entity_id', null, 'left');
I got the solution from this
By using rendere will help to load vlaues to each row.

Call specific tab on edit form in custom module in magento

I created one custom module in magento.When i click on the grid it moves to edit form where i can see three tabs like tab1,tab2,tab3.By default tab1 is selected.Now i want to add one link on grid and when customer click on that link browser redirect user to the tab3.How can i do that.My tab code as follow :
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => Mage::helper('mymodule')->__('Information'),
'title' => Mage::helper('mymodule')->__('Information'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_form')->toHtml(),
));
$this->addTab('form_section1', array(
'label' => Mage::helper('mymodule')->__(' Management'),
'title' => Mage::helper('mymodule')->__('Management'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_managment')->toHtml(),
));
$this->addTab('form_section2', array(
'label' => Mage::helper('mymodule')->__('Results'),
'title' => Mage::helper('mymodule')->__('Results'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result')->toHtml(),
));
return parent::_beforeToHtml();
}
My link code like that one on grid listing page. <a class="viewit" href="http://localhost/project/index.php/mymodule/adminhtml_mymodule/view/id/4/key/83063e416ef7f9cfb7825d01e4519293/">View</a>.My contoller function as:
public function viewAction()
{
$this->loadLayout();
$block = $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result');
// $this->_addContent($this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result'))
//->_addLeft($this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tabs'));
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
}
The code at Mage_Adminhtml_Block_Widget_Tabs::addTab suggests that tabs have property active. Try adding it to your addTab call:
$this->addTab('form_section2', array(
'label' => Mage::helper('mymodule')->__('Results'),
'title' => Mage::helper('mymodule')->__('Results'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result')->toHtml(),
'active' => true
));
Or you can extend your Grid's row URLs with parameter activeTab set to 'form_section2' (the name of the active tab) and add the following code to the _beforeToHtml function of the Tabs block class:
$param = Mage::app()->getRequest()->get('activeTab');
if (array_key_exists($param, $this->_tabs)) {
$this->_tabs[$param]->setActive();
}

Resources