我在一个jqGrid上有一些自定义的工具栏按钮。其中一个依赖于选中的行,就像内置的编辑和删除按钮一样。当用户在没有选中行的情况下单击它时,我希望用户会被呈现与内置的编辑或删除按钮相同的警告对话框。也就是说,我想重用网格使用的对话框,显示如下:
警告 请选择行
您知道网格从哪里显示警报吗?
谢谢, Scott
var alertIDs = {themodal: 'alertmod', modalhead: 'alerthd', modalcontent: 'alertcnt'};
$.jgrid.viewModal("#" + alertIDs.themodal,
{gbox: "#gbox_" + $.jgrid.jqID(this.p.id), jqm: true});
$("#jqg_alrt").focus();
在这里,this.p.id
(或$.jgrid.jqID(this.p.id)
)可以替换为网格的id。为了确保警告框能够正常工作,我建议您使用更长的代码。
var alertIDs = {themodal:'alertmod',modalhead:'alerthd',modalcontent:'alertcnt'};
if ($("#"+alertIDs.themodal).html() === null) {
$.jgrid.createModal(alertIDs,"<div>"+$.jgrid.nav.alerttext+
"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",
{gbox:"#gbox_"+$.jgrid.jqID(this.p.id),jqModal:true,drag:true,resize:true,
caption:$.jgrid.nav.alertcap,
top:100,left:100,width:200,height: 'auto',closeOnEscape:true,
zIndex: null},"","",true);
}
$.jgrid.viewModal("#"+alertIDs.themodal,
{gbox:"#gbox_"+$.jgrid.jqID(this.p.id),jqm:true});
$("#jqg_alrt").focus();
该演示 展示了代码。每次点击“Click me!”按钮时,它都会显示消息。
更新:答案 包含了如何在free jqGrid中使用上述对话框的信息。它描述了许多选项。最简单的版本只包含一个简单的调用this.modalAlert();
。它显示与free jqGrid内部显示的相同警报对话框。
我刚刚尝试了Oleg的解决方案,但对我无效。
经过一些调试,我意识到$("#"+alertIDs.themodal).html()
对于我来说是“未定义”的,因此Oleg提出的if情况没有正常工作。
我改变了这个:
if ($("#"+alertIDs.themodal).html() === null) {
把它转化为:
if ($("#"+alertIDs.themodal).html() === null || $("#"+alertIDs.themodal).html() === undefined) {
现在已经正常运行。
$.jgrid.info_dialog.call(this,
"Warning", // dialog title
"Please, select row!" // text inside of dialog
);
这对我很有效!
<table>
的“id”。此外,你代码中的$.jgrid.jqID("#tblDeltaDPSStatusEvaluation")
部分明显是错误的。你应该删除“#”,或者只用“tblDeltaDPSStatusEvaluation”替换所有内容。 - Oleg$.jgrid.info_dialog
方法来显示你的自定义消息。 - Oleg