1

Need to added grid at highlighted place.

How i can add customer grid at highlighted place ?

  • this option is not available in magento by default .You need to create your own form field to render customer grid at highlighted place. you can place customer grid in separate tab easily – Minesh Patel May 2 '16 at 9:13
  • Can we do this using custom type ? – Nimesh Patel May 2 '16 at 9:39
  • i have never tried that. but yes we can – Minesh Patel May 2 '16 at 9:44
  • Okay i will check – Nimesh Patel May 2 '16 at 9:51
5

We can display grid in admin form using custom field type

Magento admin form with grid

Form.php

<?php
class Namespace_ModuelName_Block_Adminhtml_Payment_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
    protected function _prepareForm() {
        if (Mage::registry('data')) {
            $data = Mage::registry('data')->getData();
        } else {
            $data = array();
        }

        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('wallpetpayment_walletpayment', array('legend' => Mage::helper('customer')->__('Wallet Payment')));

        $fieldset->addType('customer_grid', 'Namespace_ModuelName_Block_Adminhtml_Payment_Edit_Form_Renderer_Fieldset_Customergrid');

        $fieldset->addField('user_id', 'customer_grid', array(
            'label'     => Mage::helper('customer')->__('Customer Name'),
            'class'     => 'required-entry',
            'required'  => true,
            'name'      => 'user_id',
            'onclick' => "",
            'onchange' => "",
            'disabled' => false,
            'readonly' => false,
            'tabindex' => 1
        ));



        $fieldset->addField('amount', 'text', array(
            'label' => Mage::helper('customer')->__('Amount'),
            'class' => 'required-entry',
            'required' => true,
            'name' => 'amount',
        ));

        $wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig();
        $wysiwygConfig->addData(array('add_variables' => false,
            'add_widgets' => true,
            'add_images' => true,
            'directives_url' => Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive'),
            'directives_url_quoted' => preg_quote(Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive')),
            'widget_window_url' => Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/widget/index'),
            'files_browser_window_url' => Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg_images/index'),
            'files_browser_window_width' => (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_width'),
            'files_browser_window_height' => (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_height')
        ));

        $fieldset->addField('comment', 'editor', array(
            'name' => 'comment',
            'label' => Mage::helper('customer')->__('Remarks'),
            'title' => Mage::helper('customer')->__('Remarks'),
            'style' => 'width:800px; height:500px;',
            'config' => $wysiwygConfig,
            'required' => true,
            'wysiwyg' => true
        ));


        $form->setValues($data);

        return parent::_prepareForm();
    }
}

Now create Namespace\ModuleName\Block\Adminhtml\Payment\Edit\Form\Renderer\Fieldset\Customergrid.php

<?php
class Namespace_ModuelName_Block_Adminhtml_Payment_Edit_Form_Renderer_Fieldset_Customergrid extends Varien_Data_Form_Element_Abstract{
    protected $_element;

    public function getElementHtml()
    {
        return Mage::helper('core')->getLayout()->createBlock('blockname_node/adminhtml_payment_edit_form_renderer_fieldset_customer_grid')->toHtml();
    }
}

Then Create Namespace\ModuelName\Block\Adminhtml\Payment\Edit\Form\Renderer\Fieldset\Customer\Grid.php

<?php
class Namespace_ModuelName_Block_Adminhtml_Payment_Edit_Form_Renderer_Fieldset_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{

    public function __construct()
    {
        parent::__construct();
        $this->setId('customerGrid');
        $this->setUseAjax(true);
        $this->setDefaultSort('entity_id');
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('customer/customer_collection')
            ->addNameToSelect()
            ->addAttributeToSelect('email')
            ->addAttributeToSelect('created_at')
            ->addAttributeToSelect('group_id')
            ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
            ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
            ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
            ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
            ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');


        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn('user_id', array(
            'header'    => Mage::helper('customer')->__(''),
            'index'     => 'entity_id',
            'type' => 'radio',
            'html_name' => 'user_id',
            'align'     => 'center',
            'filter' => false
        ));

        $this->addColumn('entity_id', array(
            'header'    => Mage::helper('customer')->__('ID'),
            'width'     => '50px',
            'index'     => 'entity_id',
            'type'  => 'number',
        ));

        $this->addColumn('name', array(
            'header'    => Mage::helper('customer')->__('Name'),
            'index'     => 'name'
        ));
        $this->addColumn('email', array(
            'header'    => Mage::helper('customer')->__('Email'),
            'width'     => '150',
            'index'     => 'email'
        ));



        $this->addColumn('Telephone', array(
            'header'    => Mage::helper('customer')->__('Telephone'),
            'width'     => '100',
            'index'     => 'billing_telephone'
        ));
        return parent::_prepareColumns();
    }

    public function getGridUrl()
    {
        return $this->getUrl('adminhtml/paymenthistory/customergrid', array('_current'=> true));
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.