3

i want to create the Order Grid Serializer functionality.

If Anyone create that type functionality then please guide me..

1

Finally i figure out myself. hope it will help Community.

First add the tab for assign Order

$this->addTab('order_section', array(
         'label'     => Mage::helper('sales')->__('Assign Order'),
         'title'     => Mage::helper('sales')->__('Assign Order'),
         'url'       => $this->getUrl('*/*/assignorder', array('_current' => true)),
         'class'     => 'ajax',
      ));

Then order grid

<?php 

class SIE_Assignorder_Adminhtml_Assignorder_Edit_Tab_Grid extends Mage_Adminhtml_Block_Widget_Grid

{
public function __construct()
{
    parent::__construct();
    $this->setId('entity_id');
       $this->setDefaultDir('DESC');

    $this->setSaveParametersInSession(false);  //Dont save paramters in session or else it creates problems
    $this->setUseAjax(true);


}
protected function _prepareCollection()
   {
        $collection = Mage::getModel('sales/order')->getCollection();


        $this->setCollection($collection);
        return parent::_prepareCollection();

    }

protected function _addColumnFilterToCollection($column)
    {
     //   Set custom filter for in order flag
        if ($column->getId() == 'order_id') { 
            $sId = $this->getRequest()->getParam('id');
        $ordermodel = Mage::getModel('assignorder/checklist')->getchecklistorder($sId);
        $orderIds = "";
                 if(count($ordermodel)) {

              $orders = explode(',',$ordermodel['order_id']);
             }


            if (empty($orderIds)) { 
                $orderIds = 0;
            }
            if ($column->getFilter()->getValue() and $orderIds != 0) {  

                $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$orderIds));

            } 
            else { 
                if($orderIds) { 

                    $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$orderIds));
                }
            }
        } else {
            parent::_addColumnFilterToCollection($column);
        }
        return $this;
    }
    protected function _prepareColumns()
   {
   $this->addColumn('order_id', array(
            'header_css_class'  => 'a-center',
            'type'  => 'checkbox',
            'name'  => 'order',
            'values'=> $this->_getSelectedOrders(),
            'align' => 'center',
            'index' => 'entity_id'
        ));
    $this->addColumn('increment_id', array(
            'header'=> Mage::helper('catalog')->__('Order #'),
            'align' => 'left',
            'index' => 'increment_id',
        ));
     $this->addColumn('grand_total', array(
            'header'=> Mage::helper('catalog')->__('Grand Total'),
            'align' => 'left',
            'index' => 'grand_total',
        ));


  }

 public function getGridUrl()
    {
        return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/assignordergrid', array('_current'=>true));
    }
public function _getSelectedOrders() {

             $orders = array_keys($this->getSelectedOrders());

        return $orders;
    }

    public function getSelectedOrders() {
        $orders = array();

         $sId = $this->getRequest()->getParam('id');
        if (isset($sId)) {
            $customers=array();
           $ordermodel = Mage::getModel('assignorder/checklist')->getchecklistorder($sId);

            if(count($ordermodel))
            {
              $orders = explode(',',$ordermodel['order_id']);
              $a=0;
             }
          }

        return $orders;
    }




}

xml code

 <adminhtml_assignorder_checklist_assignorder>
       <block type="core/text_list" name="root" output="toHtml">
           <block type="assignorder/adminhtml_checklist_edit_tab_grid" name="ordersgrid"/>
           <block type="adminhtml/widget_grid_serializer" name="grid_serializer">
               <reference name="grid_serializer">
                   <action method="initSerializerBlock">
                       <grid_block_name>ordersgrid</grid_block_name>
                       <data_callback>_getSelectedOrders</data_callback>
                       <hidden_input_name>links[orders]</hidden_input_name>
                       <reload_param_name>orders</reload_param_name>
                   </action>

               </reference>
           </block>
       </block>
   </adminhtml_assignorder_checklist_assignorder>
   <adminhtml_assignorder_checklist_assignordergrid>
        <block type="core/text_list" name="root" output="toHtml">
            <block type="assignorder/adminhtml_checklist_edit_tab_grid" name="ordersgrid"/>
        </block>
   </adminhtml_assignorder_checklist_assignordergrid>

for controller

public function assignorderAction(){


    $this->loadLayout();
    $this->getLayout()->getBlock('ordersgrid')->setOrders($this->getRequest()->getPost('orders', null))
    ;
    $this->renderLayout();
}
public function assignordergridAction(){
    $sId = $this->getRequest()->getParam('id');
    $ordermodel = Mage::getModel('assignorder/checklist')->getchecklistorder($sId);
     $orders ="";
     if(count($ordermodel))
     {
    $orders = explode(',',$ordermodel['order_id']);
      }
    $this->loadLayout();
    $this->getLayout()->getBlock('ordersgrid')
    ->setOrders($this->getRequest()->getPost('orders', $order));
    $this->renderLayout();
}

getting the values of grid

if(isset($postData['links'])){
                  $orders = Mage::helper('adminhtml/js')->decodeGridSerializedInput($postData['links']['orders']); //Save the array to your database

                $orders = implode(",", $orders);


            }

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.