删除行发生时会触发哪个事件?

时间:2017-03-06 05:17:29

标签: jqgrid free-jqgrid

网格包含保存行事件" jqGridInlineAfterSaveRow"如果您编辑或添加行,它可以工作。

                //--Bind events...
            console.log('Bind events...');
            $("#jqGrid").bind("jqGridInlineAfterSaveRow",function (e, rowid, jqXhrOrBool, postData, options) {
                console.log('EVENT:jqGridInlineAfterSaveRow');
                var item = $(this).jqGrid('getLocalRow', rowid);
                console.log(item);
                console.log('BEFORE:');
                saveObject(item);
                console.log('AFTER:');
            }); 

删除行的事件名称是什么?我需要将我的JS函数绑定到删除行。

更新1 我现在正在尝试关注选项,但没有运气......

                    }).jqGrid("navGrid", "#jqGridPager", {edit: false, add: false, del: false, refresh: false, view: false,search: false,
                                                      delfunc: function (rowids) {
                                                          console.log(rowids);
                                                      }
                                                     })

更新2 我认为问题在于行级别的删除按钮而不是页脚 请参见屏幕截图[在此处输入图像说明] [1]

                        data:rdata,
                    colModel: [
                        {
                            label: "",
                            name: "",
                            width: 70,
                            formatter: "actions",
                            formatoptions: {
                                keys: true,
                                editOptions: {},
                                addOptions: {},
                                delOptions: {                        delfunc : function (id){
                                    console.log(">>>>>>>>>>>>>>>>1");
                                }}
                            }       
                        },

更新3 根据Oleg的输入,我已将代码更改为:

                $("#jqGrid").bind("jqGridAfterDelRow",function (e, rowid, jqXhrOrBool, postData, options) {
                console.log('EVENT:jqGridAfterDelRow');
                console.log(rowid);
                var item = $(this).jqGrid('delRowData ', rowid);
                console.log(item);
                console.log('BEFORE:');

                console.log('AFTER:');
            });   

但是现在,我没有删除行对象??? 实际上,我需要从删除的行中获取一些字段,例如ID。以上绑定函数将依次调用服务器端的ajax函数。

更新4 感谢Oleg 支持超越......以下是我从其中一个答案中获得mashup的代码。

                        colModel: [
                        {
                            label: "",
                            name: "",
                            width: 70,
                            formatter: "actions",
                            formatoptions: {
                                keys: true,
                                editbutton : true, 
                                delbutton : true, 
                                editOptions: {},
                                addOptions: {},
                                delOptions: {
                                    onclickSubmit: function(options, rowid) {
                                        console.log("delOptions::onclickSubmit"); 
                                        var grid_id = $.jgrid.jqID(grid[0].id);
                                        var grid_p = grid[0].p;
                                        var newPage = grid[0].p.page;
                                        var rowdata = grid.getLocalRow(rowid);

                                        // DELETE GRID LOCAL ROW
                                        grid.delRowData(rowid);
                                        $.jgrid.hideModal("#delmod"+grid_id,
                                                          {gb:"#gbox_"+grid_id,jqm:options.jqModal,onClose:options.onClose});                                            

                                        if (grid_p.lastpage > 1) {// on the multipage grid reload the grid
                                            if (grid_p.reccount === 0 && newPage === grid_p.lastpage) {
                                                // if after deliting there are no rows on the current page
                                                // which is the last page of the grid
                                                newPage--; // go to the previous page
                                            }
                                            // reload grid to make the row from the next page visable.
                                            grid.trigger("reloadGrid", [{page:newPage}]);
                                        }

                                        return true;
                                    },
                                    processing:true
                                }
                            }       
                        },

2 个答案:

答案 0 :(得分:0)

要删除代码段下方的行使用:  $( '#gridId')的jqGrid( 'delRowData',ROWID);

答案 1 :(得分:0)

您可以使用"jqGridAddEditAfterComplete"事件,该事件将在delGridRow删除行后触发,或者您可以使用"jqGridAfterDelRow",因为delGridRow调用delRowData内部jqGridAfterDelRow将由delRowData触发。