Magento – Sales Order grid new column order comment show recent comment only

ce-1.7.0.2magento-1.7order-grid

In magento CE 1.7.0.2

Add new column to sales order grid which have a most recent order comment.

Following code used to add column

protected function _prepareColumns()
{
    parent::_prepareColumns();

    // Add order comment to grid
    $this->addColumn('ordercomment', array(
        'header'       => Mage::helper('ordercomment')->__('Order Comment'),
        'index'        => 'ordercomment',
        'filter_index' => 'ordercomment_table.comment',
    ));

    // Fix integrity constraint violation in SELECT
    foreach ($this->_ambiguousColumns as $index) {
        if (isset($this->_columns[$index])) {
            $this->_columns[$index]->setFilterIndex('main_table.' . $index);
        }
    }

    return $this;
}

But comment shown in grid is first comment on order.

How most recent comment will show in this column?

Best Answer

You may need to specify a more specific data type on the addColumn:

  • action
  • checkbox
  • concat
  • country
  • currency
  • date
  • datetime
  • input
  • interface
  • ip
  • longtext
  • massaction
  • number
  • options
  • price
  • radio
  • select
  • store
  • text
  • theme
  • wrapline

You will find all these types in /app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer

You can also make your own grid renderers the same way.


If you're making comments like these, question what you're doing is correct.

//Fix integrity constraint violation in SELECT