0

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

1

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();
    }
}
  • I have already overridden the order grid with new module, Also used the Ajax method to send the data from your example however I am not getting the response ( the data doesn't saves) – Dev Sep 23 '15 at 11:47
  • Data doesn't saves, how to check if the updateNoteAction saves the data and where can I debug this ? – Dev Sep 23 '15 at 13:48
  • My problem solved, It was due to Column name misspelled... Great Thanks – Dev Sep 23 '15 at 14:59

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.