【问题标题】:jqgrid EditActionIconsColumn Eventsjqgrid EditActionIconsColumn 事件
【发布时间】:2011-07-08 22:59:42
【问题描述】:

我在网格中有一个带有 EditActionsIconsColumn 的 jqgrid,但我试图在 Edit、Del 和 Submit 上获取点击事件。 谢谢

【问题讨论】:

    标签: button jqgrid action editing


    【解决方案1】:

    formatter:'actions' 还没有很好的文档记录。当前版本的 jqGrid 3.8.2 支持您需要的一些选项。在当前版本的 jquery.fmatter.js 的lines 394-466 中可以看到更多。

    您需要的是onEditafterSave(在“提交”上)和delOptions.onclickSubmit 参数。

    说实话,我之前没有使用过“actions”格式化程序,为了理解它,我自己写了the demo,它也解决了你所有的问题。为了让其他人更容易找到示例,请在此处包含代码中最重要的部分:

    var grid = $("#list");
    grid.jqGrid({
        datatype: "local",
        data: mydata,           // init local data which will be edited
        editurl: 'clientArray', // we will use local editing
        colNames:['Actions', ... ],
        colModel:[
            {name:'act',index:'act',width:55,align:'center',sortable:false,formatter:'actions',
             formatoptions:{
                 keys: true, // we want use [Enter] key to save the row and [Esc] to cancel editing.
                 onEdit:function(rowid) {
                     alert("in onEdit: rowid="+rowid+"\nWe don't need return anything");
                 },
                 onSuccess:function(jqXHR) {
                     // the function will be used as "succesfunc" parameter of editRow function
                     // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow)
                     alert("in onSuccess used only for remote editing:"+
                           "\nresponseText="+jqXHR.responseText+
                           "\n\nWe can verify the server response and return false in case of"+
                           " error response. return true confirm that the response is successful");
                     // we can verify the server response and interpret it do as an error
                     // in the case we should return false. In the case onError will be called
                     return true;
                 },
                 onError:function(rowid, jqXHR, textStatus) {
                     // the function will be used as "errorfunc" parameter of editRow function
                     // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow)
                     // and saveRow function
                     // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#saverow)
                     alert("in onError used only for remote editing:"+
                           "\nresponseText="+jqXHR.responseText+
                           "\nstatus="+jqXHR.status+
                           "\nstatusText"+jqXHR.statusText+
                           "\n\nWe don't need return anything");
                 },
                 afterSave:function(rowid) {
                     alert("in afterSave (Submit): rowid="+rowid+"\nWe don't need return anything");
                 },
                 afterRestore:function(rowid) {
                     alert("in afterRestore (Cancel): rowid="+rowid+"\nWe don't need return anything");
                 },
                 delOptions: {
                     // because I use "local" data I don't want to send the changes to the server
                     // so I use "processing:true" setting and delete the row manually in onclickSubmit
                     onclickSubmit: function(rp_ge, rowid) {
                         // we can use onclickSubmit function as "onclick" on "Delete" button
                         alert("The row with rowid="+rowid+" will be deleted");
    
                         // reset processing which could be modified
                         rp_ge.processing = true;
    
                         // delete row
                         grid.delRowData(rowid);
                         $("#delmod"+grid[0].id).hide();
    
                         if (grid[0].p.lastpage > 1) {
                             // reload grid to make the row from the next page visable.
                             // TODO: deleting the last row from the last page which number is higher as 1
                             grid.trigger("reloadGrid", [{page:grid[0].p.page}]);
                         }
    
                         return true;
                     },
                     processing:true // !!! the most important step for the "local" editing
                                     //     skip ajax request to the server
                 }
             }},
            ...
        ],
        ...
    });
    

    【讨论】:

    • 当我使用您建议的代码时,我从 Jqgrid.min.js 收到一个错误:-“无法获取未定义或空引用的属性‘整数’”。如果我错过了什么,你能告诉我吗?我应该在数据中添加额外的列吗?
    • @Ganesh:the old demo 中是否有我为答案创建的错误?如果 在代码中 出现错误,则应创建可用于重现问题的演示(例如在 jsfiddle 中)。只有在那之后才能帮助你。例如,如果您使用旧版本的 jqGrid 并且在 jquery.jqgrid.min.js 之前未包含所需的语言环境文件 grid.locale-en.js,则可能会出现错误 Unable to get property 'integer'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    • 2011-12-30
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    相关资源
    最近更新 更多