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

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

问题描述

我添加了一个类似于相关产品的选项卡,我添加了一个类似下拉列的列:

  $ this-> addColumn('mycolumn',array(
'name'=>'mycolumn',
'header'=> Mage :: helper('catalog') - > ___ ('在当前子页面上显示'),
'index'=>'mycolumn',
'type'=>'select',
'width'=>'1 ',
'align'=>'center',
'options'=> array(
1 => Mage :: helper('catalog') - > __ '是'),
0 => Mage :: helper('catalog') - > __('否'),
),
'editable'=> true
));

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



我发现这行是在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] ));


$ / code $ / pre

我在js / mage / adminhtml / grid.js.
当我取消注释此行时,我的下拉菜单就像一个魅力...



我有两个问题关于这个问题,第一个问题是,如果它是安全的取消注释这一点(Magento必须有理由改变这一点)。



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

行解决方案

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



在网格中包含一些javascript,并添加一些自定义代码取消事件如果某些条件得到满足。
然后将复选框设置为复选。



示例将会是

  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){
//重新启用复选框
var checkbox = Element.select(element,'input );
if(checkbox [0]&&!checkbox [0] .disabled){
grid.setCheckboxChecked(checkbox [0],true);
}
return;


if(element.title){
setLocation(element.title);




$ b $ p
$ b

如果元素类型点击是一个,输入,选择或选项
其他任何将继续按照正常。

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.

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]));
        }
    }

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

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

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.

解决方案

The row click event uses a function called 'openGridRow'

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.

Example will be

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

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 select字段禁用相关产品中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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