【问题标题】:Jqgrid,dataEvent does not work for edittype:customJqgrid,dataEvent 不适用于edittype:custom
【发布时间】:2012-02-08 17:25:32
【问题描述】:

我是 jqgrid 的新手,我有一个编辑类型是自定义的列。

编辑行数据后,我希望将行保存为模糊(当我在所选行之外单击时),为此我使用了 dataEvent ,但它不起作用。

我使用的是 Jqgrid 版本 4.1。

谁能帮我解决这个问题。

我在下面附上了一段代码:

{ name: 'Roles', index: 'Roles', align: 'left', editable: true, 
  edittype: "custom",
  editoptions: {custom_element: renderRoleColumn, custom_value: roleColumnValue,
                dataEvents: [{ type: 'blur',
                               fn: function (e) {
                                    alert("roles");
                               }
                             }]
               }
}

【问题讨论】:

    标签: jquery jquery-ui jquery-plugins jqgrid


    【解决方案1】:

    你是对的。 jqGrid 的当前实现不使用dataInitdataEvents (请参阅jqGrid 的the source code 不要像所有其他编辑类型一样调用options = bindEv(elem,options))。问题只是我不确定这是一个错误。在 jqGrid 的the documentation 中描述了在edittype: "custom" 的情况下完成的所有步骤。

    我不认为这是个问题。您可以在custom_element 内进行任何绑定。您没有发布任何您使用的renderRoleColumnroleColumnValue 代码,但是如果您将blur 事件句柄绑定到您返回的自定义元素,它将起作用。

    更新:您的自定义格式化程序 renderRoleColumn 返回 <div><select><input> 元素作为子元素。 <div> 无法获得焦点,也不会处理 blur 事件。所以你应该将blur绑定到子元素<select><input>。代码可以如下所示

    function renderRoleColumn() {
        //... your current code which generate HTML fragment in the roleDiv as string
    
        // create DOM element from the HTML fragment with jQuery wrapper
        var $custom = $(roleDiv);
    
        // make binding to children
        $custom.find('select,input').blur(function (e) {
            alert('blur on ' +
                e.target.tagName.toLowerCase() +
                ' id=' + e.target.id);
        });
    
        return $custom[0]; // return roleDiv as DOM element
    }
    

    【讨论】:

    • 嗨,谢谢。 blur 事件只绑定到 'input',它不绑定到 'select' ,实际上我想保存 select 中选择的选项,你能帮我解决这个问题吗?
    • @Divya:不客气!抱歉,我用addRolesCounter = 0 测试了代码,它可以工作。您可以尝试将.blur 替换为.focusout,并在.click 上使用.focus 明确设置焦点。我的意思是做类似$custom.find('select,input').click(function (e) { $(e.target).focus(); }); 的事情。您还可以尝试使用“TAB”键将焦点设置在“选择”或“输入”上。在这种情况下,您将确定焦点已设置并且blur 也应该可以工作。
    • 非常感谢,现在我可以让 .focusout 正常工作了,我还有一个问题,关于 focusout,我希望将下拉列表中的选定选项保存在单元格中。你能帮我完成那件事吗?对不起,我是 jqgrid 的新手,发现 edittype:custom 很复杂。
    • 现在当我按下回车键时,下拉框中的选定值会保存在单元格中。我希望在 focusout 上进行相同的操作。
    猜你喜欢
    • 2010-11-28
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多