0

I'm new to Adminhtml and am using it for the first time.

In my Edit/Form.php I have a _prepareForm function which is working great, here is the code:

protected function _prepareForm()
    {  
        $model = Mage::registry('sociable_page');
        $nameValues = [];
        $serviceTitle = [];
        $serviceId = [];
        $service = Mage::getModel('sociable/service')->getCollection();
        foreach($service as $data){
            array_push($serviceTitle, $data->getTitle());
            array_push($serviceId, $data->getServicesId());
        }
        $counter = count($serviceTitle);
        for($i = 0 ; $i < $counter ; $i++){
            $serviceArray[] = array(
                    'value' => $serviceId[$i],
                    'label' => $serviceTitle[$i]
                    );
        }

        $nameValues = array(
                array('value' => 'none', 'label' => Mage::helper('sociable')->__('None')),
                array('value' => 'sociable.product_page', 'label' => Mage::helper('sociable')->__('Inside product page')),
                array('value' => 'sociable.left_top', 'label' => Mage::helper('sociable')->__('Sidebar left top')),
                array('value' => 'sociable.left_bottom', 'label' => Mage::helper('sociable')->__('Sidebar left bottom')),
                array('value' => 'sociable.right_top', 'label' => Mage::helper('sociable')->__('Sidebar right top')),
                array('value' => 'sociable.right_bottom', 'label' => Mage::helper('sociable')->__('Sidebar right bottom')),
                array('value' => 'sociable.content_top', 'label' => Mage::helper('sociable')->__('Content top')),
                array('value' => 'sociable.content_bottom', 'label' => Mage::helper('sociable')->__('Content bottom')),
            );

        $form = new Varien_Data_Form(array(
            'id'        => 'edit_form',
            'action'    => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
            'method'    => 'post'
        ));

        $fieldset = $form->addFieldset('base_fieldset', array(
            'legend'    => Mage::helper('checkout')->__('Page Information'),
            'class'     => 'fieldset-wide',
        ));

        if ($model->getId()) {
            $fieldset->addField('id', 'hidden', array(
                'name' => 'id',
            ));
        }  

        $fieldset->addField('name', 'select', array(
            'name'      => 'name',
            'label'     => Mage::helper('checkout')->__('Name'),
            'title'     => Mage::helper('checkout')->__('Name'),
            'required'  => true,
            'values'    => $nameValues,
        ));

        $fieldset->addField('services', 'multiselect', array(
            'name'      => 'services',
            'label'     => Mage::helper('checkout')->__('Services'),
            'title'     => Mage::helper('checkout')->__('Services'),
            'required'  => true,
            'values'    => $serviceArray,
        ));

        $form->setValues($model->getData());
        $form->setUseContainer(true);
        $this->setForm($form);

        return parent::_prepareForm();
    }  

The issue I'm having, is that upon saving the entry to the grid, it will display the VALUES of what was saved. I want to find a way to display the Title instead of the values. I'm thinking this would be done in Grid.php?

Here is my grid.php:

protected function _prepareColumns()
    {
        // Add the columns that should appear in the grid
        $this->addColumn('id',
            array(
                'header'=> $this->__('ID'),
                'align' =>'right',
                'width' => '50px',
                'index' => 'id'
            )
        );

        $this->addColumn('name',
            array(
                'header'=> $this->__('Name'),
                'index' => 'name'
            )
        );

        $this->addColumn('services',
            array(
                'header'=> $this->__('Services'),
                'index' => 'services'
                )
        );

        return parent::_prepareColumns();
    }

Is there a way to make the grid show something other than the values? For example, in my "Services" array, I'd like to display the LABELS in the grid instead of the values.

Thanks so much!

0

What you need is to set the column type to options in protected function _prepareColumns(). For example:

$this->addColumn('name', array(
    'header'    => Mage::helper('sociable')->__('Name'),
    'index'     => 'name',
    'type'      => 'options',
    'options'   => array(
        'sociable.product_page' => Mage::helper('sociable')->__('Inside product page')),
        'sociable.left_top' => Mage::helper('sociable')->__('Sidebar left top')),
        'sociable.left_bottom' => Mage::helper('sociable')->__('Sidebar left bottom')),
        'sociable.right_top' => Mage::helper('sociable')->__('Sidebar right top')),
        'sociable.right_bottom' => Mage::helper('sociable')->__('Sidebar right bottom')),
        'sociable.content_top' => Mage::helper('sociable')->__('Content top')),
        'sociable.content_bottom' =>  Mage::helper('sociable')->__('Content bottom'))
    ),
0

Change your Edit/Form.php file, its like

class {{ your class  }} extends Mage_Adminhtml_Block_Widget_Form
{
        protected function _prepareForm()
        {
                $form = new Varien_Data_Form(array(
                "id" => "edit_form",
                "action" => $this->getUrl("*/*/save", array("id" => $this->getRequest()->getParam("id"))),
                "method" => "post",
                "enctype" =>"multipart/form-data",
                )
                );
                $form->setUseContainer(true);
                $this->setForm($form);
                return parent::_prepareForm();
        }
}

And In your grid block define column and collection

class {{gridclass_Grid}} extends Mage_Adminhtml_Block_Widget_Grid
     extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
            parent::__construct();
            $this->setId("franchisesorderGrid");
            $this->setDefaultSort("franchises_order_id");
            $this->setDefaultDir("DESC");
            $this->setSaveParametersInSession(true);
    }
    protected function _prepareCollection()
    {
        $customerquery = new Zend_Db_Expr("( SELECT entity_id, group_concat(VALUE SEPARATOR ' ') AS franchisseholdername FROM customer_entity_varchar AS val INNER JOIN eav_attribute AS attr ON attr.attribute_id  = val.attribute_id WHERE attr.attribute_code IN ( 'firstname',  'lastname' )  GROUP BY entity_id ) "); 
        $fcollection = Mage::getModel("franchises/franchisesorder")->getCollection()->addFieldToFilter('type' , 1);
        $fcollection->getSelect()->group('main_table.return_transaction_id');
         $fcollection->getSelect() ->joinLeft($customerquery,'main_table.franchises_id = t.entity_id');
        $this->setCollection($fcollection);
        return parent::_prepareCollection();
    }
    protected function _prepareColumns()
    {
                $store = Mage::app()->getStore();
                $this->addColumn("return_transaction_id", array(
                "header" => Mage::helper("franchises")->__("Transaction #"),
                "align" =>"right",
                "width" => "50px",
                "type" => "text",
                "index" => "return_transaction_id",
                ));

Change your appropriate value and collection... only Return collection fields are display in grid column which you want to display other wise use renderer...

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.