【问题标题】:JqGrid: Setting the position for the "No Rows Selected" dialogJqG​​rid:设置“未选择行”对话框的位置
【发布时间】:2012-07-17 18:41:22
【问题描述】:

所以我找到了一些很好的修复方法,可以将确认删除、编辑、查看等对话框 here 居中。但是,如果在网格上没有选择行,则会出现一个不同的对话框,其中显示一个简单的“警告:请选择行”。除了这个对话框的语法很糟糕之外,我似乎找不到任何方法来处理这个对话框的事件,以便我可以根据需要重新定位。

我为我能找到的 navGrid 中的每个事件添加了处理程序,并使用 BugZilla 来查看它是否会在任何这些事件上停止但无济于事。 When rows are selected, it will fire the delete event fine.想法?以下是我的代码:

$('#sessionGrid').jqGrid({...}).navGrid('#sessionPager', { 
            add: false,
            edit: false,
            del: true,
            search: false,
            closeOnEscape: true
        }, {
            afterShowForm: function (form) {
                form.closest('div.ui-jqdialog').center();
            }
        }, {
            afterShowForm: function (form) {
                form.closest('div.ui-jqdialog').center();
            }
        }, {
            caption: "Delete",
            msg: "Delete the selected sessions?",
            bSubmit: "Delete",
            bCancel: "Cancel",
            afterShowForm: function (form) {
                form.closest('div.ui-jqdialog').center();
            }
        }, {
            afterShowForm: function (form) {
                form.closest('div.ui-jqdialog').center();
            }
        }, {
            afterShowForm: function (form) {
                form.closest('div.ui-jqdialog').center();
            }
        });

【问题讨论】:

    标签: jquery asp.net-mvc jqgrid


    【解决方案1】:

    grid.formedit.js 中的以下代码用于显示此对话框:

    if (o.del) {
        tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
        pDel = pDel || {};
        $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
        $("tr",navtbl).append(tbd);
        $(tbd,navtbl)
        .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
        .click(function(){
            if (!$(this).hasClass('ui-state-disabled')) {
                var dr;
                if($t.p.multiselect) {
                    dr = $t.p.selarrrow;
                    if(dr.length===0) {dr = null;}
                } else {
                    dr = $t.p.selrow;
                }
                if(dr){
                    if($.isFunction( o.delfunc )){
                        o.delfunc.call($t, dr);
                    }else{
                        $($t).jqGrid("delGridRow",dr,pDel);
                    }
                } else  {
    // !!! The actual dialog is displayed here  -
                    $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
                }
            }
            return false;
        }).hover(
            function () {
                if (!$(this).hasClass('ui-state-disabled')) {
                    $(this).addClass("ui-state-hover");
                }
            },
            function () {$(this).removeClass("ui-state-hover");}
        );
        tbd = null;
    }
    

    不幸的是,jqGrid 没有为此公开事件。但是您可能会幸运地将自己的函数绑定到删除按钮的click 事件。在同一个文件中,您可以看到 DOM ID 是如何分配给删除按钮的:

    .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
    

    本质上,您可以将id 参数作为删除参数的一部分传递,或者如果您不这样做,它将默认为elemids,它分配了您网格的DOM ID(例如:您的选择器将是'#del_mygrid')。

    无论如何,您可以在click 事件处理程序中使用类似jQuery('div.ui-jqdialog').center(); 的东西来根据需要重新定位对话框。

    这有帮助吗?


    顺便说一句,实际的对话文本在grid.locale-en.js -

    alerttext: "请选择行",

    我同意这太可怕了:) 好消息是这是一个单独的 js 文件,因此您可以根据需要对其进行修改。

    【讨论】:

    • 是的,这很有帮助。谢谢大家!
    猜你喜欢
    • 2018-08-02
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 2011-06-06
    • 1970-01-01
    相关资源
    最近更新 更多