Since sales_flat_order_item
is not included in the original sql you will get Unknown column 'sales_flat_order_item.sku'
error because that table is unknown
Try
$collection = Mage::getResourceModel('sales/order_collection')
....
->join(array('sfoi' => 'sales_flat_order_item'), 'main_table.entity_id = sfoi.order_id, array('sku'))
...
->group('main_table.entity_id')
If the example above work then undo and try
protected function _addressFilter($collection, $column)
{
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
$this->getCollection()->getSelect()
->join(array('sfoi' => 'sales_flat_order_item'), 'main_table.entity_id = sfoi.order_id, array('sku'))
->where(
"sales_flat_order_item.sku like ?"
, "%$value%");
return $this;
}
Final answer:
protected function _addressFilter($collection, $column)
{
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
$this->getCollection()->getSelect()
->join(array('sfoi' => 'sales_flat_order_item'), 'main_table.entity_id = sfoi.order_id', array('sku'))
->where(
"sfoi.sku like ?"
, "%$value%")->group('main_table.entity_id');
return $this;
}
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();
}
}
Best Answer
Remove index from addcolumn because there is no field called as category in your collection