通过setGridParam()设置jqGrid编辑选项 [英] Set jqGrid edit options via setGridParam()

查看:178
本文介绍了通过setGridParam()设置jqGrid编辑选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

初始化网格后,我需要为jqGrid的编辑事件设置一些事件处理程序.即,我需要处理beforeShowForm编辑事件.我已经尝试过使用setGridParam进行此操作,但似乎没有任何作用.

I need to set some event handlers for jqGrid's edit events after the grid has been initialized. Namely, I need to handle the beforeShowForm edit event. I have tried this using setGridParam but it doesn't seem to be doing anything.

$('#mygrid').jqGrid('setGridParam', {
    edit: {
        beforeShowForm: function(formid) {
            // handle event
        }
    }
});

jqGrid的文档不足以提供有关应该如何设置这些选项.我应该如何设置这些事后情况?我知道您可以通过jqgrid()的第二个参数进行设置.创建它后,我只需要这样做.

jqGrid's documentation is less than informative as to how these options are supposed to be set. How am I supposed to set these after-the-fact? I am aware that you can set this via the second argument for jqgrid(). I just need to do this after it has been created.

推荐答案

更改参数并不容易,因为参数保存在navGrid函数的内部变量中.因此,您应该将click事件取消绑定到编辑"按钮,并绑定新的事件,该事件调用 editGridRow 方法,其中包含您需要的所有新参数.新参数可以包括事件处理程序,例如 beforeShowForm .

You can not so easy to change parameters of edit events because the parameters are saved in internal variable of navGrid function. So you should unbind the click event to the "Edit" button and bind the new one event which call editGridRow method with all new parameters which you need. The new parameters can include event handler like beforeShowForm.

相应的代码可能与以下内容有关:

The corresponding code can be about the following:

var grid=$("#list");      // your jqGrid (the <table> element)
var grid_id = grid[0].id; // id of the <table> element like "list"
$("#edit_"+grid_id).unbind('click'); // unbind original 'click' handle
$("#edit_"+grid_id).click(function() {
    if (!$(this).hasClass('ui-state-disabled')) {
        var sr = grid[0].p.selrow;  // get id of selected row
        if (sr) {
            grid.jqGrid("editGridRow",sr,
                        { // here you should place all Edit parameters
                            beforeShowForm: function(formid) {
                                alert("In beforeShowForm()");
                            }
                        });
        } else {
            // display error message
            $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+grid_id,jqm:true});
            $("#jqg_alrt").focus();
        }
    }
    return false;
});

已更新:如果您呼叫某个地方 editGridRow 方法,并且无法更改您可以执行的代码

UPDATED: If you call somewhere editGridRow method directly and can not change the code you can make following

var grid=$("#list");      // your jqGrid (the <table> element)
var orgEditGridRow = grid.jqGrid.editGridRow; // save original function
$.jgrid.extend ({editGridRow : function(rowid, p){
    $.extend(p,
             { // modify some parameters of editGridRow
                 beforeShowForm: function(formid) {
                     alert("In new beforeShowForm()");
                 }
             });
    orgEditGridRow.call (this,rowid, p);
}});

这篇关于通过setGridParam()设置jqGrid编辑选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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