Magento:在后端数据网格的列中显示不同的操作链接

发布于 2024-11-20 13:48:55 字数 1103 浏览 10 评论 0原文

我目前正在 Magento 后端处理自定义产品列表。

这是我当前用来添加行的代码:

$this->addColumn('action_widget',
    array(
        'header'    => Mage::helper('catalog')->__('Action'),
        'width'     => '110px',
        'type'      => 'action',
        'getter'    => 'getId',
        'actions'   => array(
            array(
                'caption' => Mage::helper('catalog')->__('Create Widget'),
                'url'     => array(
                    'base'=>'*/*/create_widget',
                    'params'=>array('store'=>$this->getRequest()->getParam('store'))
                ),
                'field'   => 'id'
            )
        ),
        'filter'    => false,
        'sortable'  => false,
        'index'     => 'stores',
));

它已经按首选方式工作。

但现在我想在已经创建小部件(更新小部件)时显示另一个操作链接而不是创建链接。为了知道小部件已经创建,我将一个属性加入到集合中,该属性在不存在时为 null,在存在时为字符串。

我已经尝试使用自定义网格模板文件,将 {actionAssign} '变量'放入 url 中并在模板中分配它,但 magento url 验证拒绝了这一点。

有没有办法在没有巨大解决方法的情况下做到这一点?

如果没有,是否可以根据我的产品集合中的属性创建禁用链接?

谢谢大家! MRu

Im currently working on a custom product list in the Magento backend.

Heres the code i am currently using to add a row:

$this->addColumn('action_widget',
    array(
        'header'    => Mage::helper('catalog')->__('Action'),
        'width'     => '110px',
        'type'      => 'action',
        'getter'    => 'getId',
        'actions'   => array(
            array(
                'caption' => Mage::helper('catalog')->__('Create Widget'),
                'url'     => array(
                    'base'=>'*/*/create_widget',
                    'params'=>array('store'=>$this->getRequest()->getParam('store'))
                ),
                'field'   => 'id'
            )
        ),
        'filter'    => false,
        'sortable'  => false,
        'index'     => 'stores',
));

that works already as preferred.

But now i want to display another action link when the widget is already created (update widget) instead of the create link. To know that the widget isalready created i joined to the collection an attribute that is null when it doesn't exists or is a string when it does exist.

I've already tried to use a custom grid template file, put a {actionAssign} 'variable' into the url and assign that in the template, but the magento url validation denied that.

Is there any way to do this without a huge workaround?

If not, is it possible to create disabled links depending on the attribute in my product collection?

Thanks to everyone! MRu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

被翻牌 2024-11-27 13:48:56

以下代码对我有用。

 $this->addColumn('action',
            array(
                'header'    =>  Mage::helper('orderreminder')->__('Action'),
                'width'     => '100',
                'type'      => 'action',
                'getter'    => 'getOrderId',
                'actions'   => array(
                  array(
                        'caption'   => Mage::helper('orderreminder')->__('View Order'),
                        'url'       => array('base'=> 'adminhtml/sales_order/view'),
                        'field'     => 'order_id'
                    )
                ),
                'filter'    => false,
                'renderer'  => 'Mycompany_Mymodule_Block_Adminhtml_Template_Grid_Renderer_Myrendered',
                'sortable'  => false,
                'index'     => 'stores',
                'is_system' => true,
            ));

class Mycompany_Mymodule_Block_Adminhtml_Template_Grid_Renderer_Myrendered extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
{
    public function render(Varien_Object $row)
    {
       $value = $row->getData('increment_id');
        if($value = $row->getData('increment_id'))
            return '<a href="'.$this->getUrl('adminhtml/sales_order/view',array('order_id'=>$row->getData('order_id'))).'">View Order</a>';
        else
            return false;
    }
}

Following code is working for me.

 $this->addColumn('action',
            array(
                'header'    =>  Mage::helper('orderreminder')->__('Action'),
                'width'     => '100',
                'type'      => 'action',
                'getter'    => 'getOrderId',
                'actions'   => array(
                  array(
                        'caption'   => Mage::helper('orderreminder')->__('View Order'),
                        'url'       => array('base'=> 'adminhtml/sales_order/view'),
                        'field'     => 'order_id'
                    )
                ),
                'filter'    => false,
                'renderer'  => 'Mycompany_Mymodule_Block_Adminhtml_Template_Grid_Renderer_Myrendered',
                'sortable'  => false,
                'index'     => 'stores',
                'is_system' => true,
            ));

class Mycompany_Mymodule_Block_Adminhtml_Template_Grid_Renderer_Myrendered extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
{
    public function render(Varien_Object $row)
    {
       $value = $row->getData('increment_id');
        if($value = $row->getData('increment_id'))
            return '<a href="'.$this->getUrl('adminhtml/sales_order/view',array('order_id'=>$row->getData('order_id'))).'">View Order</a>';
        else
            return false;
    }
}
娇妻 2024-11-27 13:48:56

对于那些尝试过 Zyava 的答案但不起作用的人,您可能需要这样做:

'filter'    => false,
'renderer'  => Mage::getConfig()->getBlockClassName('mycompany_mymodule/adminhtml_template_grid_renderer_myrenderer'),
'sortable'  => false,
'index'     => 'stores',

我不知道错误在哪里,因为这不应该是必要的,但是......这是为了我。

For those of you who tried Zyava's answer and it didn't work, you might need to do this instead:

'filter'    => false,
'renderer'  => Mage::getConfig()->getBlockClassName('mycompany_mymodule/adminhtml_template_grid_renderer_myrenderer'),
'sortable'  => false,
'index'     => 'stores',

I don't know where the bug is, as this shouldn't be necessary, but... it was for me.

辞取 2024-11-27 13:48:56

有一个更简单的方法:

protected function _prepareColumns()
{
    $this->addColumn('action1',
        array(
            'type' => 'action',
            'getter' => 'getId',
            'frame_callback' => array($this, 'decorateRow'),
            'actions' => array( ... )
            'index' => 'stores',
            'is_system' => true,
        ));
    return parent::_prepareColumns();
}

public function decorateRow($sVal, Mage_Core_Model_Abstract $oRow){
    return $oRow->getData('something') ? '' : $sVal;
}

There is a simpler method:

protected function _prepareColumns()
{
    $this->addColumn('action1',
        array(
            'type' => 'action',
            'getter' => 'getId',
            'frame_callback' => array($this, 'decorateRow'),
            'actions' => array( ... )
            'index' => 'stores',
            'is_system' => true,
        ));
    return parent::_prepareColumns();
}

public function decorateRow($sVal, Mage_Core_Model_Abstract $oRow){
    return $oRow->getData('something') ? '' : $sVal;
}
情绪操控生活 2024-11-27 13:48:55

您需要为此创建自定义网格列渲染器:

  1. 创建类并重写 _transformActionData() 或 render() 方法,这取决于您到底需要什么:

    class Mycompany_Mymodule_Block_Adminhtml_Template_Grid_Renderer_Myrendered 扩展了 Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action 
    {
      ... 
    }
    
  2. 告诉 magento 为此列使用自定义渲染器:

    <前> <代码> // ...
    '过滤器' =>错误的,
    '渲染器' => 'mycompany_mymodule/adminhtml_template_grid_renderer_myrenderer',
    '可排序' =>错误的,
    '索引' => ‘商店’,
    // ...

You need create custom grid column renderer for this:

  1. Create class and override _transformActionData() or render() method, it depends on what exactly you need:

    class Mycompany_Mymodule_Block_Adminhtml_Template_Grid_Renderer_Myrendered extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action 
    {
      ... 
    }
    
  2. Tell magento to use custom renderer for this column:

    // ...
    'filter'    => false,
    'renderer'  => 'mycompany_mymodule/adminhtml_template_grid_renderer_myrenderer',
    'sortable'  => false,
    'index'     => 'stores',
    // ... 
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文