mage-enhanced-admin-grids icon indicating copy to clipboard operation
mage-enhanced-admin-grids copied to clipboard

How can i prepare my own grid to editable columns from your module?

Open simkea opened this issue 9 years ago • 13 comments

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

simkea avatar Apr 16 '15 11:04 simkea

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.

mage-eag avatar Apr 17 '15 11:04 mage-eag

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

simkea avatar May 05 '15 09:05 simkea

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)

mage-eag avatar May 06 '15 10:05 mage-eag

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.

mwgamble avatar May 25 '15 00:05 mwgamble

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 <sort_order>999999999</sort_order> but no difference

Can anyone possibly to construct an example? thx br

simkea avatar Jul 22 '15 13:07 simkea

Can someone help me? A small example would be nice.

simkea avatar Aug 20 '15 12:08 simkea

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'.

mwgamble avatar Aug 21 '15 04:08 mwgamble

Many thanks. I will try it.

simkea avatar Aug 21 '15 12:08 simkea

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 avatar Aug 21 '15 15:08 simkea

@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');
    }
}

WinstonN avatar Sep 10 '15 09:09 WinstonN

nice! i will give it a dry... br

simkea avatar Sep 11 '15 10:09 simkea

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?

simkea avatar Sep 24 '15 12:09 simkea

are you find any way ???

gh-darvishani avatar Dec 08 '16 12:12 gh-darvishani