I have made a custom grid in magento that displays saved video urls and its working. But i want to show only records where the urlid
is for example 3
. Here is my _prepareCollection
function
protected function _prepareCollection()
{
// Get and set the collection for the grid
$collection = Mage::getResourceModel('drecomm_productvideo/video_collection');
//what should i put in here, addFieldtoSelect?
$this->setCollection($collection);
return parent::_prepareCollection();
}
my grid extends from Mage_Adminhtml_Block_Widget_Grid
and there is no addFieldToFilter
function in that class.
First of all, if you want to create a permanent filter for your collection (meaning that you will not be able to remove it from your grid view) you should use addFieldToFilter
to your collection object. This method is not a part of grid
class, it's the part of collection class.
$collection = Mage::getResourceModel('drecomm_productvideo/video_collection')
->addFieldToFilter('urlid', 3);
Now if you want to just add a default filter for you collection (meaning that it will be applied from the start, but you'll be able to reset it and see all entries), you should use setDefaultFilter()
method of your grid block.
protected function _construct()
{
parent::_construct();
//... your code
$this->setDefaultFilter(array('urlid' => 3));
}