jQuery 模态对话框和 jqGrid

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3587480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:42:53  来源:igfitidea点击:

jQuery modal dialog and jqGrid

jqueryjqgridmodal-dialogconfirmation

提问by paul

How can I use the Jquery modal confirmation with jqGrid? Say when I will submit my entries it will pop up a modal dialog and display the names with the message for sending to server..

如何在 jqGrid 中使用 Jquery 模式确认?说当我提交我的条目时,它会弹出一个模式对话框并显示名称以及发送到服务器的消息。

My approach

我的方法

$("#dialog-confirm").dialog({
            autoOpen:false,
            resizable:false,
            height:180,
            modal:true,
            buttons:{
                 'Confirm': function(){
                            var ids =jQuery("#list10").jqGrid('getGridParam','selarrrow');
                                $.ajax({
                                  type: "POST",
                                  url: "url&names="+ids,
                                  data: JSON.stringify(ids), 
                                  dataType: "json"
                            });
                                },
                            'cancel': function(){
                                    $(this).dialog('close');
                                    }
        }
        });
        });

my html :

我的 HTML :

<div id="dialog-confirm" title="Confirm">
        <p><span class="ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Are you sure want to cancel(or send this names)#names?</p>
    </div>

In that dialog box I need to send those names as well... but this approach will not give me the names from my grid which I selected to send it to server.

在那个对话框中,我也需要发送这些名称......但这种方法不会从我选择将它发送到服务器的网格中给我名称。

回答by Oleg

The following code could do what you need

下面的代码可以做你需要的

$("#wics").click( function(){
    var grid = jQuery("#list10");
    var ids = grid.jqGrid('getGridParam','selarrrow');
    if (ids.length>0) {
        var names = [];
        for (var i=0, il=ids.length; i < il; i++) {
            var name = grid.jqGrid('getCell', ids[i], 'Name');
            names.push(name);
        }
        //alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));
        $("#names").html(names.join(", "));
        $("#dialog-confirm").dialog({
            height:280,
            modal:true,
            buttons:{
                'Cancel': function(){
                    $(this).dialog('close');
                },
                'Confirm': function(){
                    //alert("Confirm");
                    $.ajax({
                        type: "POST",
                        url:  "/cpsb/unprocessedOrders.do",
                        data: { method: "releaseTowics",
                            orderNum: JSON.stringify(ids),
                            names: JSON.stringify(names)
                        },
                        dataType: "json",
                        success: function(msg){
                            alert(msg);
                        },
                        error: function(res, status, exeption) {
                            alert(res);
                        }
                    });
                }
            }
        });
    }
});

The exact solution of cause will depends on your requirement on the server side. You can try this (without ajax request) here http://www.ok-soft-gmbh.com/jqGrid/DataToMultiSelect2.htm. Select some items and click "Get Selected" button. 

原因的确切解决方案将取决于您对服务器端的要求。您可以在http://www.ok-soft-gmbh.com/jqGrid/DataToMultiSelect2.htm尝试此操作(无需 ajax 请求)。选择一些项目,然后单击“获取选择”按钮。