Magento 选择字段禁用相关产品中的行 [英] Magento select field disables row in related products

查看:17
本文介绍了Magento 选择字段禁用相关产品中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个功能类似于相关产品的选项卡,我添加了一个带有如下下拉列表的列:

I have added a tab with functionality similar to related products, I have added a column with a dropdown like this:

$this->addColumn('mycolumn', array(
        'name' => 'mycolumn',
        'header' => Mage::helper('catalog')->__('Display on current child page'),
        'index' => 'mycolumn',
        'type' => 'select',
        'width' => '1',
        'align' => 'center',
        'options' => array(
        1 => Mage::helper('catalog')->__('Yes'),
        0 => Mage::helper('catalog')->__('No'),
    ),
        'editable' => true
    ));

每次我更改选择时,我的产品都会被取消选中并且该行被禁用.

Everytime i change the selection my product gets unchecked and the row is disabled.

我发现magento中注释了这一行:

I found that this line was commented in magento:

     bindFieldsChange : function(){
        if (!$(this.containerId)) {
            return;
        }
 --->  //     var dataElements = $(this.containerId+this.tableSufix).down('.data tbody').select('input', 'select');
        var dataElements = $(this.containerId+this.tableSufix).down('tbody').select('input', 'select');
        for(var i=0; i<dataElements.length;i++){
            Event.observe(dataElements[i], 'change', dataElements[i].setHasChanges.bind(dataElements[i]));
        }
    }

我在 js/mage/adminhtml/grid.js 中找到了这段代码.当我取消注释这一行时,我的下拉菜单就像一个魅力......

I found this code in js/mage/adminhtml/grid.js. When I uncommented this line my dropdown worked like a charm...

关于这个问题我有 2 个问题,第一个问题是取消注释是否安全(Magento 一定有理由改变它).

I have 2 questions regarding this matter, the first one would be if it's safe to uncomment this (Magento must've had a reason to change this).

我的第二个问题是如何在不调整 grid.js 文件的情况下避免这种行为.我不喜欢以任何方式编辑核心文件,但无法弄清楚如何重写此功能或如何以行为不适用的方式添加我的列.

My second question is how I could avoid this behaviour without adjusting the grid.js file. I dislike editing corefiles in any way but am unable to figure out how to rewrite this functionality or how to add my column in a manner that the behaviour does not apply itself.

推荐答案

行点击事件使用了一个名为'openGridRow'的函数

The row click event uses a function called 'openGridRow'

在您的网格中包含一些 javascript,并使用一些自定义代码添加此函数以在满足某些条件时取消事件.然后将复选框设置回选中状态.

Include some javascript with your grid, and add this function with some custom code to cancel the event if certain conditions are met. Also then set the checkbox back to checked.

示例将是

function openGridRow(grid, event){
                var element = Event.findElement(event, 'tr');
                //alert(Event.element(event).tagName.toLowerCase());
                if(Event.element(event).type != 'checkbox'){
                  if(['img', 'a', 'input', 'select', 'option', 'img'].indexOf(Event.element(event).tagName.toLowerCase())!=-1) {
                      // re-enable the checkbox
                      var checkbox = Element.select(element, 'input');
                      if(checkbox[0] && !checkbox[0].disabled){
                          grid.setCheckboxChecked(checkbox[0], true);
                      }
                      return;
                  }
                }
                if(element.title){
                    setLocation(element.title);
                }
    }    

上面的例子什么都不做,如果点击的元素类型是a, input, select or option其他一切都将照常进行.

The above example will do nothing, if the element type clicked is a, input, select or option Anything else will continue as per normal.

这篇关于Magento 选择字段禁用相关产品中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆