1

I had created 4 custom fields for the Order:

pgs_order_website_names
pgs_aramex_reference
pgs_aramex_shipped
pgs_aramex_shipped_date

I had copied Grid.php to local/Mage/

class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid

Constructor

public function __construct()
{
    parent::__construct();
    $this->setId('sales_order_grid');
    $this->setUseAjax(true);
    $this->setDefaultSort('created_at');
    $this->setDefaultDir('DESC');
    $this->setSaveParametersInSession(true);
}

The _prepareCollection() Method :

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $select = $collection->getSelect();
    $select->joinLeft(array(
                        'order' => Mage::getModel('core/resource')->getTableName('sales/order')),
                        'order.entity_id=main_table.entity_id',
                        array(
                        'pgs_order_website_names' => 'pgs_order_website_names',
                        'pgs_aramex_reference'=>'pgs_aramex_reference',
                        'pgs_aramex_shipped'=>'pgs_aramex_shipped',
                        'pgs_aramex_shipped_date'=>'pgs_aramex_shipped_date'
                        )
                    ); 
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

The _prepareColumns() Method

protected function _prepareColumns()
{
    $this->addColumn('pgs_order_website_names', array(
        'header'=> Mage::helper('sales')->__('Ordered Websites'),
        'index' => 'pgs_order_website_names',
        'width' => '80px',
        'type'  => 'text',
        'filter' => false,

    ));
    $this->addColumn('pgs_aramex_reference', array(
        'header'=> Mage::helper('sales')->__('Aramex ref. No'),
        'index' => 'pgs_aramex_reference',
        'width' => '80px',
        'type'  => 'text',
        'filter' => false,

    ));
    $this->addColumn('pgs_aramex_shipped', array(
        'header'=> Mage::helper('sales')->__('Sent to Warehouse ?'),
        'index' => 'pgs_aramex_shipped',
        'width' => '80px',
        'type'  => 'text',
        'filter' => false,

    ));
    $this->addColumn('pgs_aramex_shipped_date', array(
        'header'=> Mage::helper('sales')->__('Sent to Warehouse ?'),
        'index' => 'pgs_aramex_shipped_date',
        'width' => '80px',
        'type'  => 'date',
        'filter' => false,
    ));
return parent::_prepareColumns();

}

Everythig is working fine if i make the 'filter' attribute to false in $this->addColumn() Method! But if i changed to true im getting an error :

Fatal error: Call to a member function setColumn() on a non-object The column attributes are :

$dateAttribute  = array(
    'type'          => 'date',
    'backend_type'  => 'date',
    'frontend_input' => 'date',
    'is_user_defined' => true,
    'label'         => 'Shipped date',
    'visible'       => true,
    'required'      => false,
    'user_defined'  => false,   
    'searchable'    => false,
    'filterable'    => true,
    'comparable'    => false,

);

Magento CE 1.9

7
  • What does your __construct() method look like? Also make sure you are setting to use AJAX in the construct $this->setUseAjax(true); Normally filterable is default as true more than likely you're missing a defined index in your collection or a callback function to sort in the collection. magento.stackexchange.com/a/118022/69
    – B00MER
    Commented Aug 10, 2016 at 8:46
  • Use Alias in your join section, like below : Commented Aug 10, 2016 at 12:48
  • @B00MER im getting an error if tries to search any order ::Integrity constraint violation: 1052 Column 'increment_id' in where clause is ambiguous, query was: SELECT main_table.*, order.pgs_order_website_names, order.pgs_aramex_reference, order.pgs_aramex_shipped, order.pgs_aramex_shipped_date FROM sales_flat_order_grid AS main_table LEFT JOIN sales_flat_order AS order ON order.entity_id=main_table.entity_id WHERE (increment_id LIKE '%2800%') ORDER BY created_at DESC LIMIT 20
    – Shan
    Commented Aug 10, 2016 at 15:13
  • 1
    @Shan magento.stackexchange.com/a/12279/69
    – B00MER
    Commented Aug 10, 2016 at 16:46
  • 1
    @B00MER Solved the problem while searching with default fields, still problem exists with custom filelds if i set 'filter'=> true
    – Shan
    Commented Aug 11, 2016 at 6:00

1 Answer 1

1
+50

Try to use Alias in your join section, like below :

$select->joinLeft(array(
                    'order' => Mage::getModel('core/resource')->getTableName('sales/order')),
                    'order.entity_id=main_table.entity_id',
                    array(
                    'pgs_order_website_names' => 'order.pgs_order_website_names',
                    'pgs_aramex_reference'=>'order.pgs_aramex_reference',
                    'pgs_aramex_shipped'=>'order.pgs_aramex_shipped',
                    'pgs_aramex_shipped_date'=>'order.pgs_aramex_shipped_date'
                    )

EDIT : Also use column names with Aliases like 'filter_index'=>'main_table.increment_id' in addColumn method e.g.

 $this->addColumn('order_id', array(
'header' => Mage::helper('sales')->__('Order Id'),
'align' =>'left',
'index' => 'increment_id',
'filter_index'=>'main_table.increment_id',

));

8
  • I tried this already, But it was not working .. please see the comment above regarding sql integrity error
    – Shan
    Commented Aug 10, 2016 at 16:47
  • You are getting that integrity error because, 'increment_id' exists in both joining tables i.e. main_table and order tables Commented Aug 11, 2016 at 6:31
  • Please check my above edited answer @Shan Commented Aug 11, 2016 at 6:55
  • Ahsan Thanks buddy, You pointed me in right direction, Actually "order.field_name" solved my problem completely !!!
    – Shan
    Commented Aug 16, 2016 at 14:12
  • Great to hear this from you :) @Shan Commented Aug 17, 2016 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.