2012-08-14 138 views
4

我在jqGrid上有一些自定義工具欄按鈕。其中一個依賴於被選中的行,就像內置的編輯和刪除按鈕一樣。當用戶在沒有選擇行的情況下單擊它時,我希望用戶從內置的「編輯」或「刪除」按鈕中獲得與它們相同的警告對話框。也就是說,我想重用電網使用,說對話:jqGrid警告對話框

警告 請選擇行

任何想法,電網從顯示警報?

感謝, 斯科特

回答

7

我認爲該代碼可能看起來像下面

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(); 

The demo演示了代碼。它顯示消息

enter image description here

當你點擊 "Click me!"按鈕每次

已更新:The answer包含如何使用上述對話框的信息free jqGrid。它描述了很多選項。最簡單的版本只包含一個簡單的調用this.modalAlert();。它顯示與jqGrid內部顯示的免費jqGrid相同的警報對話框。

+0

工程很好。謝謝。現在要弄清楚你是怎麼想出來的;) – 2012-08-14 21:24:33

+1

哇,這工作正常。但我想稍微改變一下。我想更改消息框的文本和標題以在不同的實例中顯示不同的消息。如何實現? – Amit 2013-01-30 06:13:13

+0

@Amit:在演示中,顯式使用'$ .jgrid.nav.alerttext'作爲消息的文本,'$ .jgrid.nav.alertcap'作爲標題。您可以直接將'$ .jgrid.nav.alerttext'和'$ .jgrid.nav.alertcap'替換爲另一個文本或使用'$ .expend($。jgrid.nav,{alerttext:「new text」,alertcap: 「new title」});'更改默認警報消息的文本。 – Oleg 2013-01-30 06:25:24

2

我剛剛嘗試過Oleg的下面的解決方案,它不適合我。
做一些調試我意識到$("#"+alertIDs.themodal).html()對我來說是'未定義的',所以如果Oleg提出的情況不能正常工作。

我改變了這個:

if ($("#"+alertIDs.themodal).html() === null) { 

到這一點:

if ($("#"+alertIDs.themodal).html() === null || $("#"+alertIDs.themodal).html() === undefined) { 

,現在是工作的罰款。

-1
$.jgrid.info_dialog.call(this, 
    "Warning",    // dialog title 
    "Please, select row!" // text inside of dialog 
); 

它適合我!

+0

他要求使用相同的警報,這意味着與JQGrid默認值相同的本地化消息。 – jstuardo 2017-01-05 23:38:40