2

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;
}

1 Answer 1

1

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

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.