Magento 1.9 Order Grid – Add Textarea in Order Grid View

magento-1.9order-gridrenderer

How to insert a personal note or text area on order grid page for each order, This should save when entered the text. is that possible using Renderer. If there is any module for this please suggest, or some code hints would be helpful.enter image description here

Best Answer

Create a custom module*

Then create a custom render:

class Module_NameSpace_Block_Adminhtml_Widget_Grid_Column_Renderer_Inline
    extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input
{
    public function render(Varien_Object $row)
    {
        $html = parent::render($row);
        $html .= '<button onclick="updateNote(this, '. $row->getId() .'); return false">' . Mage::helper('modulename')->__('Update') . '</button>';
        return $html;
    }
}

after wards extend the Block / rewrite the Grid and add your column:

$this->addColumn('note', array(
    'header'           => Mage::helper('modulename')->__('Note'),
    'align'            => 'center',
    'renderer'         => 'modulename/adminhtml_widget_grid_column_renderer_inline',
    'index'            => 'note',
));

No its time to update the config.xml and add a custom layout:

<adminhtml>
    <layout>
        <updates>
            <module_namespace>
                <file>namespace_module.xml</file>
            </module_namespace>
        </updates>
    </layout>
</adminhtml>

add your layout file in app/design/adminhtml/default/default/layout/namespace.xml:

<?xml version="1.0"?>
<layout>
    <adminhtml_modulename_index>
        <reference name="js">
            <block type="core/template" template="namespace/modulename/inline-edit.phtml" />
        </reference>
    </adminhtml_modulename_index>
</layout>

finally create the layout file app/design/adminhtml/default/default/template/namespace/modulename/inline-edit.phtml

<script type="text/javascript">
function updateNote(button, fieldId)
{
    new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/backendcontroller/updateNote') ?>', {
        method: 'post',
        parameters: { id: fieldId, note: $(button).previous('input').getValue() }
    });
}
</script>

and add updateNote in your backend controller:

public function updateNoteAction()
{
    $fieldId = (int) $this->getRequest()->getParam('id');
    $note = $this->getRequest()->getParam('note');
    if ($fieldId) {
        $model = Mage::getModel('modulename/model')->load($fieldId);
        $model->setNote($note);
        $model->save();
    }
}
Related Topic