4

i am using showlink Formatter of JQGrid. for this my colModel is

[
{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}}
];

i want to make link having two request parameters which will be part of my jqgrid data as:

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

but i am getting error

Uncaught ReferenceError: unit is not defined 

but if i make change as

[
    {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'}}
    ];

i am getting url

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

but i want value of unit should be depending on that row,

here is Example i created.

alternate approach i used is writing custom wrap function. but i want to use default "showlink" Formatter. please help.

swapy
  • 1,616
  • 1
  • 15
  • 31
  • I am not sure if you can get the value of another column. Why don't you use a custom formatter? – RRK Jun 11 '13 at 17:11

1 Answers1

2

In colModel userId column mention formatter: editLink for get the values of userId and isActive, here editLink is a function.

columnIndex userId is first parameter, columnIndex isActive is second parameter, get these values using rowdata.userId and rowdata.isActive in editLink function. These two value are separated using &.

Pass two parameters in URL using jqgrid.

Code:

$(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>";
        }
UdayKiran Pulipati
  • 6,579
  • 7
  • 67
  • 92