Jqgrid,dataEvent 不适用于 edittype:custom

发布于 2025-01-03 17:14:26 字数 599 浏览 0 评论 0原文

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

I'm new to jqgrid, I have a column whose edit type is custom.

Once the row data is edited , I want the row to be saved on blur (when i click outside of the selected row), for this purpose i made use of dataEvent , but it does not work.

I'm using Jqgrid version4.1.

Can someone please help me to resolve this issue.

I have attached a piece of my code below:

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

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

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

发布评论

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

评论(1

橙幽之幻 2025-01-10 17:14:26

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

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

更新:您的自定义格式化程序renderRoleColumn返回

,其中包含。代码可以像下面这样

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
}

You are right. The current implementation of jqGrid don't use dataInit or dataEvents on the (see the source code of jqGrid don't call options = bindEv(elem,options) like for all other edittypes). The problem is only that I am not sure that it's a bug. In the documentation of jqGrid described really all steps which are done in case of edittype: "custom".

I don't see that it's a problem. You can make any bindings inside of custom_element. You don't posted any code of renderRoleColumn and roleColumnValue which you use, but if you would bind blur event handle to the custom element which you returned it will be work.

UPDATED: Your custom formatter renderRoleColumn returns <div> with <select> and <input> elements as children. The <div> can't have focus and will don't process blur event too. So you should bind blur to the child elements <select> and <input>. The code can be like the following

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文