【问题标题】:Custom grid button to load ajax content depending on selected row自定义网格按钮根据所选行加载 ajax 内容
【发布时间】:2012-10-18 16:13:29
【问题描述】:

我需要在我的网格中创建一个自定义按钮,该按钮将打开一个模式,该模式将根据所选行呈现带有选项的选择字段。

因此用户将选择一行并单击按钮。行 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 

并填充模态...

提前致谢。

【问题讨论】:

    标签: jqgrid struts2 struts2-jquery


    【解决方案1】:

    我找到了解决方案。在此发帖,希望对其他人有所帮助。

    我最终使用普通的旧 jquery 脚本来显示模式而不是 jquery-plugin。

    只需构造您的操作 url 添加所需的参数并调用 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();
            }
        });
    });
    

    在您的操作中,您必须使用相应的 getter 和 setter 声明一个与您的 url 参数(在我的例子中为 nrProcesso)同名的变量。

    【讨论】:

      猜你喜欢
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-14
      • 1970-01-01
      相关资源
      最近更新 更多