0

I have Grid which has 4 serialzed input it could be look something like

Below is just eg.

<script type="text/javascript">
new serializerController('id_27b4a99055d89f87349b56c924404a36', {"1":{"price":"0,000","position":"4"},"2":{"price":"14,000","position":"5"}}, ["price","position"], specificationGrid_1JsObject, 'specifications');

But my controller object contain like

<script type="text/javascript">
new serializerController('id_f0526caaa5cb152f3a0282ec6884026e', [1605,1730,1977,2121], ["shouldsendwarrantymail","shouldsendfactorymail","shouldsendordermail"], customerGridJsObject, 'customer');

My Grid File.

<?php
class Shipping_Shippinggroup_Block_Adminhtml_Shippinggroup_Edit_Tab_Formcustomer extends  Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('customerGrid');
        $this->setUseAjax(true); // Using ajax grid is important
        $this->setDefaultSort('id');
        $this->setSaveParametersInSession(true);  //Dont save paramters in session or else it creates problems
        $this->setAdditionalJavaScript("
        // added click on selectbox support
        serializerController.prototype.rowClick = serializerController.prototype.rowClick.wrap(function(o, grid, event) {
            var tagName = Event.element(event).tagName
                isSelect = (tagName == 'SELECT' || tagName == 'OPTION');
            if (!isSelect) {
                o(grid, event);
            }
        });
        ");
    }



    protected function _getStore()
    {
        $storeId = (int) $this->getRequest()->getParam('store', 0);
        return Mage::app()->getStore($storeId);
    }

    protected function _prepareCollection()
{

    $store = $this->_getStore();
    $groupId = $this->getRequest()->getParam('id');

    $collection = Mage::getResourceModel('customer/customer_collection')
    ->addNameToSelect()
    ->addAttributeToSelect('entity_id')
    ->addAttributeToSelect('email')
    ->addAttributeToSelect('created_at')
    ->addAttributeToSelect('group_id')
    ->addFieldToFilter('group_id',array('in' => array(5)));
    $this->setCollection($collection);

    return parent::_prepareCollection();
}



    protected function _prepareColumns()
    {
        $this->addColumn('customer_ids', array(
            'header_css_class'  => 'a-center',
            'type'              => 'checkbox',
            'name'              => 'customer_ids',
            'values'            => $this->_getSelectedCustomers(),
            'align'             => 'center',
            'index'             => 'entity_id'
        ));


        $this->addColumn('shouldsendwarrantymail', array(
            'name'              => 'shouldsendwarrantymail',
            'index'             => 'shouldsendwarrantymail',
            'header'    => Mage::helper('customer')->__('Should Send Warranty Mail'),
            'type'              => 'select',
            'options'   => array('0'=>'No','1'=>'Yes'),
            'filter'    => false,
            'sortable'  => false,


        ));

        $this->addColumn('shouldsendfactorymail', array(
            'name'              => 'shouldsendfactorymail',
            'index'             => 'shouldsendfactorymail',
            'header'    => Mage::helper('customer')->__('Should Send Factory Mail'),
            'type'              => 'select',
            'options'   => array('0'=>'No','1'=>'Yes'),
            'filter'    => false,
            'sortable'  => false


        ));
        $this->addColumn('shouldsendordermail', array(
            'name'              => 'shouldsendordermail',
            'index'             => 'shouldsendordermail',
            'header'    => Mage::helper('customer')->__('Should Send Order Mail'),
            'type'              => 'select',
            'options'   => array('0'=>'No','1'=>'Yes'),
            'filter'    => false,
            'sortable'  => false


        ));


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


        return parent::_prepareColumns();
    }

    public function getRowUrl($row) {
        return false;
    }

    protected function _getSelectedCustomers()   // Used in grid to return selected customers values.
    {
        $customers = $this->getSelectedCustomers();
        return $customers;
    }

    public function getSelectedCustomers()
    {
        // Customer Data

        $tm_id = $this->getRequest()->getParam('id');

        if(!isset($tm_id)) {
            $tm_id = 0;
        }

            $custIds = array();
            $customerProductIds = Mage::getModel('shippinggroup/shippinggroupcustomer')->getCollection()->addFieldToFilter('shippinggroup_id', array(
                     array('finset' => $tm_id)));
                    // print_r($customerProductIds->getData());
            foreach($customerProductIds as $id){
                $custIds[$id->getCustomerIds()] = array(
                                                        'shouldsendwarrantymail' => $id->getShouldsendwarrantymail(),
                                                        'shouldsendfactorymail' => $id->getShouldsendfactorymail(),
                                                        'shouldsendordermail' => $id->getshouldsendordermail(),
                                                        );
            }

        //var_dump($custIds);exit;
        return array_keys($custIds);
    }

    /**
     * Rerieve grid URL
     *
     * @return string
     */
    public function getGridUrl()
    {
        return $this->getUrl('*/*/customergrid', array('_current'=>true));
    }

}

Layout file

<shippinggroup_adminhtml_shippinggroup_customers>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="shippinggroup/adminhtml_shippinggroup_edit_tab_formcustomer" name="shippinggroup.edit.tab.formcustomer" />
        <block type="adminhtml/widget_grid_serializer" name="customer_grid_serializer" >
                <action method="initSerializerBlock">
                    <grid_block_name>shippinggroup.edit.tab.formcustomer</grid_block_name>
                    <data_callback>getSelectedCustomers</data_callback>
                    <hidden_input_name>links[customer_ids]</hidden_input_name>
                    <reload_param_name>customer</reload_param_name>
                </action>
                <action method="addColumnInputName">
                   <input_name>shouldsendwarrantymail</input_name>
                   <input_name>shouldsendfactorymail</input_name>
                   <input_name>shouldsendordermail</input_name>
               </action>
        </block>
    </block>
</shippinggroup_adminhtml_shippinggroup_customers>
0

Ok got the answer from my self.

 public function getSelectedCustomers()
{
    // Customer Data

    $tm_id = $this->getRequest()->getParam('id');

    if(!isset($tm_id)) {
        $tm_id = 0;
    }

        $custIds = array();
        $customerProductIds = Mage::getModel('shippinggroup/shippinggroupcustomer')->getCollection()->addFieldToFilter('shippinggroup_id', array(
                 array('finset' => $tm_id)));
                // print_r($customerProductIds->getData());
        foreach($customerProductIds as $id){
            $custIds[$id->getCustomerIds()] = array(
                                                    'shouldsendwarrantymail' => $id->getShouldsendwarrantymail(),
                                                    'shouldsendfactorymail' => $id->getShouldsendfactorymail(),
                                                    'shouldsendordermail' => $id->getshouldsendordermail(),
                                                    );
        }


    return $custIds; /* it should return full array */
}

For column value

$this->addColumn('customer_ids', array(
        'header_css_class'  => 'a-center',
        'type'              => 'checkbox',
        'name'              => 'customer_ids',
        'values'            => array_keys($this->_getSelectedCustomers()),
        'align'             => 'center',
        'index'             => 'entity_id'
    ));

Important function from layout file

<data_callback>getSelectedCustomers</data_callback>

above define function is responsible to generate json

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.