【问题标题】:adding dynamic parameter in showlink formatter of JQGrid在 JQGrid 的 showlink 格式化程序中添加动态参数
【发布时间】:2012-07-12 23:36:54
【问题描述】:

我正在使用 JQGrid 的 showlink 格式化程序。 为此,我的 colModel 是

[
{name:'id',index:'id',hidden:true}, 
{name:'unit',index:'unit',sorttype:"string"},
{name:'supplierName',index:'supplierName',sorttype:"string",formatter:'showlink',formatoptions:{baseLinkUrl:'supplierCommodityDetail',addParam: '&unit='+unit}}
];

我想让链接有两个请求参数,这将是我的 jqgrid 数据的一部分:

http://localhost:7654/kiss/portal/yoadmintool/supplierCommodity/supplierCommodityDetail?id=48803&unit=Unit1

但我遇到了错误

Uncaught ReferenceError: unit is not defined 

但如果我做出改变

[
    {name:'id',index:'id',hidden:true}, 
    {name:'unit',index:'unit',sorttype:"string"},
    {name:'supplierName',index:'supplierName',sorttype:"string",formatter:'showlink',formatoptions:{baseLinkUrl:'supplierCommodityDetail',addParam: '&unit=abc'}}
    ];

我正在获取网址

http://localhost:7654/kiss/portal/yoadmintool/supplierCommodity/supplierCommodityDetail?id=48803&unit=abc

但我希望单位的值应该取决于该行,

这是我创建的Example

我使用的另一种方法是编写自定义包装函数。但我想使用默认的“showlink”格式化程序。 请帮忙。

【问题讨论】:

  • 我不确定您是否可以获取另一列的值。为什么不使用自定义格式化程序?

标签: javascript jquery jqgrid jqgrid-formatter


【解决方案1】:

colModel userId 列中提到formatter: editLink 以获取userIdisActive 的值,这里editLink 是一个函数。

columnIndex userId 是第一个参数,columnIndex isActive 是第二个参数,使用editLink 函数中的rowdata.userIdrowdata.isActive 获取这些值。这两个值使用& 分隔。

使用 jqgrid 在 URL 中传递 two parameters

代码:

$(document).ready(function(){
            //jqGrid
            $("#usersList").jqGrid({
                url:'<%=request.getContextPath() %>/Admin/getAllUsersList',
                datatype: "json",               
                colNames:['Edit','Primary Email','Active','First Name','Middle Name','LastName','Mobile Number'],
                colModel:[
                    {name:'userId',search:false,index:'userId',width:30,sortable: false,formatter: editLink},                       
                    {name:'email',index:'user.primaryEmail',width:150},
                    {name:'isActive',index:'user.isActive',width:80},
                    {name:'firstName',index:'firstName', width:100},
                    {name:'middleName',index:'middleName', width:100},
                    {name:'lastName',index:'lastName', width:100},
                    {name:'mobileNo',index:'user.mobileNo', width:100},
                    ],
                    rowNum:20,
                    rowList:[10,20,30,40,50],
                    rownumbers: true,  
                    pager: '#pagerDiv',
                    sortname: 'user.primaryEmail',  
                    viewrecords: true,  
                    sortorder: "asc",
                    autowidth:'true',
            });
            $('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%");
            $('.ui-jqgrid-bdiv').css('height', window.innerHeight * .65);
            $('#load_usersList').width("130");
            $("#usersList").jqGrid('navGrid','#pagerDiv',{edit:false,add:false,del:false},{},{},{}, {closeAfterSearch:true});
            $(".inline").colorbox({inline:true, width:"20%"});
        });

        function editLink(cellValue, options, rowdata, action)
        {
            return "<a href='<%=request.getContextPath()%>/Admin/editUser/" +rowdata.userId+"&"+rowdata.isActive  + "' class='ui-icon ui-icon-pencil' ></a>";
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多