Magento:在后端数据网格的列中显示不同的操作链接
我目前正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下代码对我有用。
Following code is working for me.
对于那些尝试过 Zyava 的答案但不起作用的人,您可能需要这样做:
我不知道错误在哪里,因为这不应该是必要的,但是......这是为了我。
For those of you who tried Zyava's answer and it didn't work, you might need to do this instead:
I don't know where the bug is, as this shouldn't be necessary, but... it was for me.
有一个更简单的方法:
There is a simpler method:
您需要为此创建自定义网格列渲染器:
创建类并重写 _transformActionData() 或 render() 方法,这取决于您到底需要什么:
告诉 magento 为此列使用自定义渲染器:
<前> <代码> // ...
'过滤器' =>错误的,
'渲染器' => 'mycompany_mymodule/adminhtml_template_grid_renderer_myrenderer',
'可排序' =>错误的,
'索引' => ‘商店’,
// ...
You need create custom grid column renderer for this:
Create class and override _transformActionData() or render() method, it depends on what exactly you need:
Tell magento to use custom renderer for this column: