I've created an adminhtml grid which is supposed to map Block Positions to Services. For example: The block "Sidebar right Bottom" could be linked to Facebook, Twitter, Instagram and then that block would have those 3 services linked in it.
The issue I'm having, is that the column "Services" is displaying the IDs of the services, instead of their Titles. I've tried to rectify this issue by modifying my Grid.php file:
protected function _prepareColumns()
{
// Add the columns that should appear in the grid
$this->addColumn('id',
array(
'header'=> $this->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'id'
)
);
// $this->addColumn('name',
// array(
// 'header'=> $this->__('Name'),
// 'index' => 'name'
// )
// );
$this->addColumn('name', array(
'header' => Mage::helper('sociable')->__('Name'),
'index' => 'name',
'type' => 'options',
'options' => array(
'sociable.product_page' => Mage::helper('sociable')->__('Inside product page'),
'sociable.left_top' => Mage::helper('sociable')->__('Sidebar left top'),
'sociable.left_bottom' => Mage::helper('sociable')->__('Sidebar left bottom'),
'sociable.right_top' => Mage::helper('sociable')->__('Sidebar right top'),
'sociable.right_bottom' => Mage::helper('sociable')->__('Sidebar right bottom'),
'sociable.content_top' => Mage::helper('sociable')->__('Content top'),
'sociable.content_bottom' => Mage::helper('sociable')->__('Content bottom')
),
));
$serviceTitle = [];
$serviceId = [];
$service = Mage::getModel('sociable/service')->getCollection();
foreach($service as $data){
array_push($serviceTitle, $data->getTitle());
array_push($serviceId, $data->getServicesId());
}
$counter = count($serviceTitle);
$serviceArray = [];
for($i = 0 ; $i < $counter ; $i++){
$serviceArray[$serviceId[$i]] = $serviceTitle[$i];
}
$this->addColumn('services',
array(
'header'=> $this->__('Services'),
'index' => 'services',
'type' => 'options',
'options' => $serviceArray,
)
);
return parent::_prepareColumns();
}
I've tried providing the services field with "options" and passing in the array of services which is created by mapping the ID of the service to the Title of the service. The Array looks like so:
Array(
[1] => Facebook
[2] => Twitter
etc...
)
When the multi-select field is set with only 1 value, the grid will display the value as needed. However if multiple values are selected, the grid will display nothing. Here is a screenshot to illustrate:
Here is how it looks when I remove the "options" from the services field:
I'm hoping that when multiple values are saved, it will be stored in the Grid like so: "Diigo, Twitter, Facebook" ... etc. Similar to how the IDs are stored in the second image.
Any ideas on how I can resolve this issue?
Thanks so much!