i have created custom grid at admin side. in grid i created dropdown list. but when i select any value from dropdown for searching, then search is not working...
C:\xampp2\htdocs\testmagento\app\code\local\Sigmasolve\Makemodel\Block\Adminhtml\Makemodel\Grid.php
<?php
class Sigmasolve_Makemodel_Block_Adminhtml_Makemodel_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('makemodelGrid');
// This is the primary key of the database
$this->setDefaultSort('id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('makemodel');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('makemodel')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete', array('' => '')),
'confirm' => Mage::helper('makemodel')->__('Are you sure?')
));
return $this;
}
protected function _prepareCollection()
{
$collection = Mage::getModel('makemodel/makemodel')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addExportType('*/*/exportCsv', Mage::helper('makemodel')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('makemodel')->__('XML'));
$this->addColumn('id', array(
'header' => Mage::helper('makemodel')->__('Id'),
'align' =>'right',
'width' => '50px',
'index' => 'id',
));
$this->addColumn('manufacturer', array(
'header' => Mage::helper('makemodel')->__('Manufacturer'),
'align' =>'left',
'index' =>'manufacturer',
'type' =>'options',
'options'=> Mage::getModel('makemodel/makemodel')->getManufacturers()
));
$this->addColumn('model', array(
'header' => Mage::helper('makemodel')->__('Model'),
'align' =>'left',
'index' => 'model',
'type' =>'options',
'options'=> Mage::getModel('makemodel/makemodel')->getModels()
));
$this->addColumn('capacity', array(
'header' => Mage::helper('makemodel')->__('Capacity'),
'align' =>'left',
'index' => 'capacity',
'type' =>'options',
'options'=> Mage::getModel('makemodel/makemodel')->getCapacitys()
));
$this->addColumn('year_from', array(
'header' => Mage::helper('makemodel')->__('Year-From'),
'align' =>'left',
'index' => 'year_from',
'type' =>'options',
'options'=> Mage::getModel('makemodel/makemodel')->getYearFroms()
));
$this->addColumn('year_to', array(
'header' => Mage::helper('makemodel')->__('Year-To'),
'align' =>'left',
'index' => 'year_to',
'type' =>'options',
'options'=> Mage::getModel('makemodel/makemodel')->getYearTos()
));
$this->addColumn('fuel', array(
'header' => Mage::helper('makemodel')->__('Fuel'),
'align' =>'left',
'index' => 'fuel',
'type' =>'options',
'options'=> Mage::getModel('makemodel/makemodel')->getFuels()
));
$this->addColumn('ktyp', array(
'header' => Mage::helper('makemodel')->__('KTYP'),
'align' =>'left',
'index' => 'ktyp',
));
$this->addColumn('engine_code', array(
'header' => Mage::helper('makemodel')->__('Engine code'),
'align' =>'left',
'index' => 'engine_code',
));
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
C:\xampp2\htdocs\testmagento\app\code\local\Sigmasolve\Makemodel\Model\Makemodel.php
<?php
class Sigmasolve_Makemodel_Model_Makemodel extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('makemodel/makemodel');
}
public function getManufacturers() {
$manufacturersArray = array();
$ManufacturerCollection = Mage::getModel('makemodel/makemodel')->getCollection();
$ManufacturerCollection->getSelect()->group('manufacturer');
$ManufacturerCollection->setOrder('manufacturer', 'ASC');
foreach($ManufacturerCollection->getData() as $manufacturer){
$manufacturersArray[$manufacturer['id']] = $manufacturer['manufacturer'];
}
return $manufacturersArray;
}
/* public function getModels() {
$modelsArray = array();
foreach($this->getCollection() as $model){
$modelsArray[$model->getId()] = $model->getModel();
}
return $modelsArray; // All Commented Code For My Refference......
} */
public function getModels() {
$modelsArray = array();
$ModelCollection = Mage::getModel('makemodel/makemodel')->getCollection();
$ModelCollection->getSelect()->group('model');
$ModelCollection->setOrder('model', 'ASC');
foreach($ModelCollection->getData() as $model){
$modelsArray[$model['id']] = $model['model'];
}
return $modelsArray;
}
public function getCapacitys() {
$capacitysArray = array();
$CapacityCollection = Mage::getModel('makemodel/makemodel')->getCollection();
$CapacityCollection->getSelect()->group('capacity');
$CapacityCollection->setOrder('capacity', 'ASC');
foreach($CapacityCollection->getData() as $capacity){
$capacitysArray[$capacity['id']] = $capacity['capacity'];
}
return $capacitysArray;
}
public function getYearFroms() {
$yearfromsArray = array();
foreach($this->getCollection() as $yearfrom){
$yearfromsArray[$yearfrom->getId()] = $yearfrom->getYearFrom();
}
return $yearfromsArray;
}
public function getYearTos() {
$yeartosArray = array();
foreach($this->getCollection() as $yearto){
$yeartosArray[$yearto->getId()] = $yearto->getYearTo();
}
return $yeartosArray;
}
public function getFuels() {
$fuelsArray = array();
$FuelCollection = Mage::getModel('makemodel/makemodel')->getCollection();
$FuelCollection->getSelect()->group('fuel');
$FuelCollection->setOrder('fuel', 'ASC');
foreach($FuelCollection->getData() as $fuel){
$fuelsArray[$fuel['id']] = $fuel['fuel'];
}
return $fuelsArray;
}
}
-
Will it return any error ? Do you have any values in your model ? for exactly which column your are facing issues.Krishna ijjada– Krishna ijjada2017年01月27日 06:26:20 +00:00Commented Jan 27, 2017 at 6:26
-
@krishna ijjada at i95Dev ......... i have not get any error. but when i search any field from dropdown search result is empty...Rushikesh Solanki– Rushikesh Solanki2017年01月27日 06:28:55 +00:00Commented Jan 27, 2017 at 6:28
-
You can try with static data, if it works fine then we can try with dynamic. Means $this->addColumn('your_column_name', array( 'header' => Mage::helper('catalog')->__('your attribute label'), 'index' => 'your_attribute_code', 'type' => 'options', 'options' => array('Option 1', 'Option 2', ....) ));Krishna ijjada– Krishna ijjada2017年01月27日 06:33:07 +00:00Commented Jan 27, 2017 at 6:33
-
it is also not workRushikesh Solanki– Rushikesh Solanki2017年01月27日 06:43:26 +00:00Commented Jan 27, 2017 at 6:43
-
Try with only one field, you may get confuse with lot of values. later will add.Krishna ijjada– Krishna ijjada2017年01月27日 06:54:00 +00:00Commented Jan 27, 2017 at 6:54
1 Answer 1
I think here is the problem :
$this->addColumn('manufacturer', array(
'header' => Mage::helper('makemodel')->__('Manufacturer'),
'align' =>'left',
'index' =>'manufacturer',
'type' =>'options',
'options'=> Mage::getModel('makemodel/makemodel')->getManufacturers()
));
In above code you have mention index=>manufacturer while in below code you are passing id as a index
public function getManufacturers() {
$manufacturersArray = array();
$ManufacturerCollection = Mage::getModel('makemodel/makemodel')->getCollection();
$ManufacturerCollection->getSelect()->group('manufacturer');
$ManufacturerCollection->setOrder('manufacturer', 'ASC');
foreach($ManufacturerCollection->getData() as $manufacturer){
$manufacturersArray[$manufacturer['id']] = $manufacturer['manufacturer'];
}
return $manufacturersArray;
}
So just replace to
$manufacturersArray[$manufacturer['id']] = $manufacturer['manufacturer'];
from
$manufacturersArray[$manufacturer['manufacturer']] = $manufacturer['manufacturer'];
I hope this will work.
Explore related questions
See similar questions with these tags.