jqGrid:在“编辑”表单中添加“删除”按钮(jqGrid: Adding a Delete button to the Edit form)

编程入门 行业动态 更新时间:2024-10-25 14:33:47
jqGrid:在“编辑”表单中添加“删除”按钮(jqGrid: Adding a Delete button to the Edit form)

我是一个jqGrid新手。 我需要在“编辑”表单中添加“删除”按钮。 我能够添加按钮,它会按预期显示,包括确认对话框,但一旦按下我不知道如何引用原始行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删除功能? 谢谢!

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 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字符串。

所以你可以修改beforeShowForm回调到

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);
    ...
}

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.

So you can modify beforeShowForm callback to

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

or to the following

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

                    
                     
          

更多推荐

jqGrid,function,row_id,I'm,电脑培训,计算机培训,IT培训"/> <meta name=&qu

本文发布于:2023-08-08 01:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466756.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   按钮   编辑   jqGrid   Adding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!