I have created custom collection with Varien_Data_Collection
in admin grid like below :
protected function _prepareCollection() {
$collection = Mage::getModel("catalog/product")->getCollection()
->addAttributeToFilter('entity_id', array('in' => $productIds))
->addAttributeToSelect($attributes)
->addAttributeToSelect("sku")
->addWebsiteFilter($websiteID)
->addAttributeToFilter("type_id", "simple");
$dataArray = array();
foreach($collection as $item)
{
$productID = $item->getData('product_id');
$req_qty = Mage::helper("purchasemanagement")->getRequiredQty($productID);
$dataArray[$item->getId()] = $item->getData();
$dataArray[$item->getId()]['req_qty'] = $req_qty;
}
usort($dataArray,array($this, '_sortItems'));
$new_collection = new Varien_Data_Collection();
foreach($dataArray as $row){
$rowObj = new Varien_Object();
$rowObj->setData($row);
$new_collection->addItem($rowObj);
}
$this->setCollection($new_collection);
return parent::_prepareCollection();
}
But now i am not able to filter in this custom collection. I get the below error :
Call to undefined method Varien_Data_Collection::addFieldToFilter() in app\code\core\Mage\Adminhtml\Block\Widget\Grid.php on line 472
I tried to follow these two links :
1) Filtering error when using custom Varien object collection in admin grid
2) Magento 1 : Filtering / Paging / Sorting with Varien_Data_Collection
but none of them worked. Can anyone tell me how to implement the solution ?
Thanks in advance.