javascript – 在JQGrid的showlink格式化程序中添加动态参数

我正在使用showlink Formatter of JQGrid.

为此,我的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”格式化程序.
请帮忙.

最佳答案 在colModel userId列中提到formatter:editLink用于获取userId和isActive的值,这里editLink是一个函数.

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

使用jqgrid在URL中传递两个参数.

码:

$(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>";
        }
点赞