2012-10-18 28 views
0

我需要在我的網格中創建一個自定義按鈕,將打開一個模式,這將根據選定的行呈現選項字段的選項。自定義網格按鈕加載ajax內容取決於選定的行

所以用戶將選擇一行並點擊按鈕。行ID應該作爲URL參數傳遞給我的操作,以便它可以進行查詢並填充選擇字段。

這是我掙扎:

navigatorExtraButtons="{ 
    honorarios:{ 
     title: 'Consultar honorários do processo', 
     caption: 'H', 
     icon: 'none', 
     onclick: function(){ 
      var id = jQuery('#processoTable').jqGrid('getGridParam','selrow'); 
      if (id) { 
       var ret = jQuery('#processoTable').jqGrid('getRowData',id); 
       // need to pass ret.nrProcesso as param to the URL that will load content into the modal 
      } else { alert('Please select a row.');} 
     } 
    }, 

隨着上面的代碼是否可以從選擇的行所希望的ID值。但我不知道如何將它分配給

<s:url... param 

和填充模態...預先

感謝。

回答

1

我找到了解決方案。張貼在這裏希望它可以幫助別人。

我已經結束了使用普通的舊jQuery腳本來獲取模式顯示,而不是jQuery插件。

只是構建您的行動網址添加需要的參數,調用一個Ajax功能:

<sj:submit id="consulta_honorarios" value="Consultar Honorários" onClickTopics="honorarios" button="true"/> 
<sj:dialog 
    id="mydialog" 
    title="Consultar honorários" 
    autoOpen="false" 
    modal="true" 
    dialogClass="ui-jqdialog" 
/> 

<script type="text/javascript"> 
jQuery(document).ready(function(){ 
    jQuery("#consulta_honorarios").click(function(){ 
     var actionURL = '<s:property value="%{advprocselecturl}" />'; 
     var id = jQuery('#processoTable').jqGrid('getGridParam','selrow'); 
     if (id) { 
      var ret = jQuery('#processoTable').jqGrid('getRowData',id); 
      actionURL += '?nrProcesso=' + ret.nrProcesso; 
      // alert('id='+ret.nrProcesso+'/actionURL='+actionURL); 
      jQuery.ajax({ 
       url: actionURL 
      }).done(function(data){ 
       jQuery('#mydialog').html(data).dialog('open'); 
      }); 
     } else { 
      jQuery('<div />').html('Por favor, selecione um registro.').dialog(); 
     } 
    }); 
}); 

在你的行動,你必須聲明一個變量具有相同的名稱作爲您的URL參數(nrProcesso在我的情況)與相應的吸和二傳手。