Magento – magento admin product grid add category filter to admin grid without adding column

admincustomfiltergridproduct

i am trying to filter grid by category without adding category column, is there a way by which we can do this custom filter to grid.

below is what i did

function prepareCollection()
{
$catIdArray = getRequest()->getParam('cat_id');
//i.e  $catIdArray = array(26, 27, 17);

$collection = Mage::getModel('catalog/product')->getCollection(); 

$collection->joinField(
    'category_id',
    'catalog/category_product',
    'category_id',
    'product_id=entity_id',
    null,
    'left'
)
->addAttributeToFilter( 
    'category_id',
    array('in' => $catIdArray)
)
->addAttributeToSelect('*');
$this->setCollection($collection);

Here filter is working fine, but pagination doesn't work in this case. please suggest me what am i doing wrong????

Best Answer

Try this:

$this->joinTable(
    'catalog/category_product', // table to join
    'product_id=entity_id', // ON statement, flat table first!
    array(), // don't add any columns
    array('in' => $categoryIds) // additional WHERE
);