Custom Multiple Columns Filter in Magento Admin Order Grid

collection-filteringfiltergridmagento-1.9

i am adding multiple columns in magento order grid they are working fine as separate filter but when choose multiple column nothing shown

if ($block->getId() == 'sales_order_grid') { 
             $data=Mage::getModel('name/name')->getCollection()->setOrder('position','ASC');
            foreach($data as $dat)
            {
            $block->addColumnAfter(
                'some name',
                array(
                    'header'   => 'name',
                    'align'    => 'left',
                    'index'    =>  $dat->getId(),
                      'renderer'  => 'renderer class',

                    'sortable'  => false,

                    'type' => 'options',
                    'options' => $this->_getOptions($dat->getId()),

                    'filter_condition_callback' => array($this, '_filtercolumn'),

                ),
                'id_of_column_to_be_after'
            );
             $block->sortColumnsByOrder();
            }
        }

this is filter code

public function _filtercolumn($collection, $column)
    {
        if (!$value = trim($column->getFilter()->getValue())) { 
        return;
    }
$collection->getSelect()->join('tablename')->where("`tablename`.order_id=`main_table`.entity_id AND `tablename`.column1='$value' AND  `tablename`.column2='$columnid'");

    $collection->printLogQuery(true);


    return $collection;
}

Best Answer

Query is not wrote properly,please try this

$collection->getSelect()->join(array('tablename' => 'YOURTABLENAME'),
            'tablename.order_id = =`main_table`.entity_id'  
        AND `tablename`.column1='$value' AND  `tablename`.column2='$columnid'",
            array('*')
        );

Make clone of collection on _filtercolumn function if required and then add join query on clone

$cloneCollection=clone $collection
Related Topic