简体   繁体   English

jqGrid删除带有确认对话框的行

[英]jqGrid deleted row with confirm dialog

i am using struts2-jquery-jqgrid. 我正在使用struts2-jquery-jqgrid。 i have buttons in the columns of the grid. 我在网格的列中有按钮。 i need to implement a confirm dialog when user clicks to delete. 当用户单击删除时,我需要实现一个确认对话框。

SOLUTION: 解:

// JAVASCRIPT THAT ADD BUTTONS IN THE COLUMN AND EVENT CLICK //在列中添加按钮并单击事件的JAVASCRIPT

$.subscribe('gridCompleteTopics2', function() {
var ids = jQuery("#gridtable2").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++){
    var fila = jQuery("#gridtable2").jqGrid("getRowData", ids[i]);      
    link = "<button id='opener' onClick='deleteRecord(" + fila["idplanilla_det"]        + ");'>Open Dialog</button>";   
    jQuery("#gridtable2").jqGrid('setRowData',ids[i],{acti:link});  
}   
 });

function deleteRecord(id) {
alert(id);    
$("#dialogo").dialog("open");
}

$(function() {
$( "#dialog" ).dialog({
    autoOpen: false,
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "ACEPTAR": function() {
          $( this ).dialog( "close" );
        },
        "CANCELAR": function() {
          $( this ).dialog( "close" );
        }
      }
    });    
   });

<div id="dialog" title="Empty the recycle bin?">

These items will be permanently deleted and cannot be recovered. 这些项目将被永久删除,无法恢复。 Are you sure? 你确定吗?

WORK. 工作。

First of all, you should not have multiple controls with the same ID. 首先,您不应有多个具有相同ID的控件。 Here, you are creating ids.length -many buttons with id opener . 在这里,您正在使用id opener创建ids.length许多按钮。 Instead, assign a class to the buttons, eg opener . 而是为按钮分配一个类,例如opener

Then, you should move your .opener click function after the buttons were created, as such: 然后,应在创建按钮后移动.opener click功能,如下所示:

$.subscribe("gridCompleteTopics2", function () {
    var ids = jQuery("#gridtable2").jqGrid("getDataIDs");
    for (var i = 0; i < ids.length; i++) {
        var fila = jQuery("#gridtable2").jqGrid("getRowData", ids[i]);
        link = "<button id='opener'>Open Dialog</button>";
        jQuery("#gridtable2").jqGrid("setRowData", ids[i], { acti: link });
    }

    $(".opener").on("click", function() {
        $("#dialog").dialog("open");
    }); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM