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))
                    ->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();

        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.

1 Answer 1


You can try with below method, YOu can remove $rowObj = new Varien_Object(); and directly set inside collection,

    $new_collection = new Varien_Data_Collection();
    foreach($dataArray as $row){
        if (isset($row)) {
    return parent::_prepareCollection();
  • still not working.! Commented Apr 28, 2017 at 10:24
  • I get this error "Recoverable Error: Argument 1 passed to Varien_Data_Collection::_getItemId() must be an instance of Varien_Object, array given" when i remove "$rowObj = new Varien_Object();" Commented Apr 28, 2017 at 12:22

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.