7

Is there a way (or several ways) to add additional columns to the sales order grid which one sees in the admin area?

1
  • I think the question might a bit too broad since depending on what additional column you want to display the solution would look different since one might require a join and another can take the information straight from the sales_order_grid table. It would also be good if you spelled out what properly means to you. To me it could mean anything between not hacking the core to no rewrites and making the new columns filterable. – Kristof at Fooman Jan 26 '13 at 12:30
5

I'd do it clean.

I'd observe core_collection_abstract_load_before and adminhtml_block_html_before events.

In the fist one I'd add joinAttribute(), joinField() and join() to the collection and in the second I'd addColumn() to the block.

Let me know if more details are required.

2
  • You'd consume all of the collection loads? Why not just observe Mage_Sales_Model_Resource_Order_Grid_Collection? – benmarks Jan 24 '13 at 18:54
  • Sorry, I'm just thinking further. Thinking about solution to modify any admin grid. – user487772 Jan 24 '13 at 19:15
1

If you have a custom module that needs to add columns, this probably wont be for you, but for adding the payment method or something to the grid, this works fine: https://github.com/mage-eag/mage-enhanced-admin-grids

1

You want to extend Mage_Adminhtml_Block_Sales_Order_Grid in app/code/local/Module/Adminhtml/Block/Sales/Order, override the function _prepareColumns() and use $this->addColumn. If you need to modify the collection to alter the SQL for the collection being used, override _prepareCollection() and call Mage::getResourceModel($this->_getCollectionClass())->getSelect()->joinLeft(...)

For both functions, return the result of Mage_Adminhtml_Block_Widget_Grid::_prepareCollection() or Mage_Adminhtml_Block_Widget_Grid::_prepareColumns() rather than the parent or your changes will get overwritten with the original behavior from Mage_Adminhtml_Block_Sales_Order_Grid.

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.