jqGrid:将“删除"按钮添加到“编辑"表单 [英] jqGrid: Adding a Delete button to the Edit form

查看:92
本文介绍了jqGrid:将“删除"按钮添加到“编辑"表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jqGrid新手.我需要在编辑"表单中添加一个删除"按钮.我能够添加按钮,它会按预期显示,包括确认对话框,但是一旦按下,我不确定如何引用原始行ID:

I'm a jqGrid newbie. I need to add a Delete button to the Edit form. I'm able to add the button, and it shows up as expected, including the confirmation dialog, but once pressed I'm not sure how to refer to the original row id:

// Add a Delete button in Edit form:
    $.extend($.jgrid.edit, {
        bSubmit: "Submit",
        bCancel: "Cancel",
        width: 370,
        recreateForm: true,
        beforeShowForm: function () {
            $('<a href="#">Delete<span class="ui-icon ui-icon-circle-close"></span></a>')
                .click(function() {
                    if(confirm("Are you sure you want to delete this record?")) {
                        $("#projectList").jqGrid('delGridRow', row_id);
                    }
                }).addClass("fm-button ui-state-default ui-corner-all fm-button-icon-left")
                  .prependTo("#Act_Buttons>td.EditButton");
        }
    });

上面代码中的

row_id未定义..如何在代码中从该位置引用当前选定行的ID?上面的函数当前与其他主要jqGrid函数并行,例如$(#projectList").jqGrid({..}).或更妙的是,如何从这里挂接默认的jqGrid删除功能? 谢谢!

row_id in the code above is not defined .. How can I refer to the id of the currently selected row from this place in the code? The function above is currently parallel to the other main jqGrid functions, such as $("#projectList").jqGrid({ .. }). Or better, how can I hook into the default jqGrid delete function from here? Thank you!

推荐答案

要获取beforeShowForm内部编辑行的rowid,您可以使用以下事实:编辑表单中包含一些隐藏的行,这些行中的信息可能对您有所帮助. 添加/编辑"对话框的隐藏行中的输入字段为id ="id_g".输入字段包含编辑行的ID.添加对话框在字段中包含_empty字符串.

To get rowid of the editing row inside of beforeShowForm you can use the fact that editing form have some hidden rows with information which could be helpful for you. Add/Edit dialog has input field in the hidden row with the id="id_g". The input field contains the id of editing row. Add dialog contains _empty string in the field.

因此您可以将beforeShowForm回调修改为

So you can modify beforeShowForm callback to

beforeShowForm: function () {
    var row_id = $("#id_g").val();
    ...
}

或以下

beforeShowForm: function ($form) {
    var row_id = $("#id_g", $form).val(), $self = $(this);
    ...
    $self.jqGrid('delGridRow', row_id);
    ...
}

这篇关于jqGrid:将“删除"按钮添加到“编辑"表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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