Open simkea opened 9 years ago
You need to create a grid type model (check BL_CustomGrid_Model_Grid_Type_Cms_Block
for a simple example), and register it in the etc/customgrid.xml
file of your module, with this minimal code :
<?xml version="1.0"?>
<customgrid>
<grid_types>
<your_grid_type model="yourmodule/grid_type_custom_name" module="yourmodule">
<name>Name</name>
<sort_order>100</sort_order>
</your_grid_type>
</grid_types>
</customgrid>
Note that in the 1.0.0 version, the base class for grid type models (BL_CustomGrid_Model_Grid_Type_Abstract
) will include some non backwards compatible changes, that will require some small adaptations.
Hello, i am not able to do :(
here my xml: app/code/local/Simkea/Slider/etc/customgrid.xml
<?xml version="1.0"?>
<customgrid>
<grid_types>
<slideritem type="slider/grid_type_slideritem" module="slider"><!-- model -->
<name>Slideritem</name>
<sort_order>1000000001</sort_order>
</slideritem>
</grid_types>
</customgrid>
app/code/local/Simkea/Slider/Model/Grid/Type/Slideritem.php
class Simkea_Slider_Model_Grid_Type_Slideritem extends BL_CustomGrid_Model_Grid_Type_Abstract
{
public function isAppliableToGrid($type, $rewritingClassName)
{
return ($type == 'slider/adminhtml_slideritem_grid');
}
protected function _getBaseEditableFields($type)
{
$helper = Mage::helper('slider');
$fields = array(
'is_active' => array(
'type' => 'select',
'required' => true,
'form_options' => array(
'1' => $helper->__('Enabled'),
'0' => $helper->__('Disabled'),
),
)
);
return $fields;
}
protected function _getEntityRowIdentifiersKeys($type)
{
return array('slideritemid');
}
protected function _loadEditedEntity($type, $config, $params)
{
Mage::log($params);
if (isset($params['ids']['slideritemid'])) {
return Mage::getModel('slider/slideritem')->load($params['ids']['slideritemid']);
}
return null;
}
}
my grid: app/code/local/Simkea/Slider/Block/Adminhtml/Slideritem/Grid.php
<?php
class Simkea_Slider_Block_Adminhtml_Slideritem_Grid extends Mage_Adminhtml_Block_Widget_Grid {
public function __construct() {
parent::__construct();
$this->setId("slideritemGrid");
$this->setDefaultSort("slideritemid");
$this->setDefaultDir("ASC");
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
$this->setVarNameFilter('product_filter');
}
protected function _prepareCollection() {
$collection = Mage::getModel("slider/slideritem")->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn("slideritemid", array(
"header" => Mage::helper("slider")->__("ID"),
"align" => "right",
"width" => "30px",
"type" => "number",
"index" => "slideritemid",
));
$this->addColumn('is_active', array(
'header' => Mage::helper('slider')->__('Status'),
'index' => 'is_active',
'type' => 'options',
'options' => array(
0 => Mage::helper('slider')->__('Disabled'),
1 => Mage::helper('slider')->__('Enabled')
),
));
return parent::_prepareColumns();
}
public function getRowUrl($row) {
return $this->getUrl("*/*/edit", array("id" => $row->getId()));
}
}
I would like to enable the dataset from grid.
I believe i need help. thx
Can you test with a lower sort_order
in your grid type definition ? (there may be a bug preventing user-defined grid types from being used in certain cases, no matter what sort order they are given - if you still can't get it to work, I'll give you some changes to apply in the extension code)
Before #172 was accepted and merged, it was not possible to define your own custom grid types unless your module's configuration was loaded before that of the EAG extension. Once you have the patch from #172, the only thing that is necessary is to ensure your custom grid type's sort order value is lower than that of the fallback "Other" grid type.
I am stuck with my problem :( ... Is that even possible? Is that possible with its own grid/model
I use mage-enhanced-admin-grids 1.0.0-wip and Magento 1.9.1.1
and i try sort_order
Can anyone possibly to construct an example? thx br
Can someone help me? A small example would be nice.
It looks like you're overriding the wrong method. Instead of overriding isAppliableToGrid
, you should be overriding _getSupportedBlockTypes
. In this method, you should return an array containing 'slider/adminhtml_slideritem_grid'.
Many thanks. I will try it.
I beleave my customgrid.xml from my Module is not read by CustomGrid...
`class Simkea_Slider_Model_Grid_Type_Slideritem extends BL_CustomGrid_Model_Grid_Type_Abstract {
protected function _getSupportedBlockTypes()
{
return array('slider/adminhtml_slideritem_grid');
}
protected function _getBaseEditableFields($blockType)
{
/** @var $helper Simkea_Slider_Helper_Data */
$helper = Mage::helper('slider');
$fields = array(
'title' => array(
'type' => 'text',
'required' => true,
'form_note' => $helper->__('TITLE'),
),
);
return $fields;
}
protected function _getEntityRowIdentifiersKeys($blockType)
{
return array('slideritemid');
}
protected function _loadEditedEntity($blockType, BL_CustomGrid_Object $config, array $params, $entityId)
{
/** @var $page Simkea_Slider_Model_Slideritem */
$page = Mage::getModel('slider/slideritem');
$page->load($entityId);
return $page;
}
protected function _getEditRequiredAclPermissions($blockType)
{
return 'slider/slideritem';
}
} `
if i set a "Mage::log()" i cant see any logs from this model?!... not loading?! Why?! thx
@simkea I have done this, and it works for me. In your module you must have a /etc/customgrid.xml file in this file you can set something like
<?xml version="1.0"?>
<customgrid>
<grid_types>
<controller_name type="module_name/grid_type_order" module="module_name">
<name>Orders</name>
<sort_order>30000</sort_order>
</controller_name>
</grid_types>
</customgrid>
Then in your Model/Grid/Type/Order.php
<?php
class Company_Modulename_Model_Grid_Type_Order
extends BL_CustomGrid_Model_Grid_Type_Order
{
public function isAppliableToGrid($type, $rewritingClassName)
{
return (($type == 'modulename/adminhtml_path_to_grid')
|| ($type == 'modulename/adminhtml_path_to_grid'));
}
protected function _isOrdersGrid()
{
return true;
}
protected function _getItemsCustomColumnModel($customizable=false)
{
return 'customgrid/custom_column_order_items_'.($customizable ? 'custom' : 'default');
}
}
nice! i will give it a dry... br
mmmh... i believe my own Grid Type is ignored by EAG ?!
my class only an part:
app/code/local/Simkea/Slider/etc/customgrid.xml
<customgrid>
<grid_types>
<slideritem type="slider/grid_type_slideritem" module="slider"><!-- model -->
<name>Slideritem</name>
<sort_order>30001</sort_order>
</slideritem>
</grid_types>
</customgrid>
app/code/local/Simkea/Slider/Model/Grid/Type/Slideritem.php
class Simkea_Slider_Model_Grid_Type_Slideritem extends BL_CustomGrid_Model_Grid_Type_Abstract {
function __construct(){
Mage::log(__METHOD__);
}
protected function _getSupportedBlockTypes()
{
Mage::log(__METHOD__);
}
...
}
I can not see any comments in my logfiles.
What is the problem?
@WinstonN i need an editable column in my grid for an complete own model... it is possible too?
are you find any way ???
Hello,
i have an own module with model and backend grid. what can i do to prepare my grid or model that one column is editable about your module mage-enhanced-admin-grids?
thx for help? br Henry