Reputation: 1041
I want to add an extra parameter in the jqgrid . The below code is not working
formatoptions:{baseLinkUrl:'loadHoldCode/id=?', addParam: '&customerId='+$('#custIdHidden').val()},
but If I hard code the parameter value, then the value is passed as I wanted.
formatoptions:{baseLinkUrl:'loadHoldCode/id=?', addParam: '&customerId="123"},
Please help me what I should change or should I follow some other approach.
UPDATE: using custom Formater, i have tried and still I am not seeing any link
name: 'holdCode',
width: 100,
formatter:function (cellvalue, options, rowObject) {
return '<a src="loadHoldCode/id=?&customerId=' + rowObject.customerId + '">' +
cellvalue + "</a>";},
searchoptions:{sopt: ['cn', 'eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni']},
sortable: true,
editable: false
Upvotes: 0
Views: 1895
Reputation: 1750
Instead of using the predefined formatter
showlink, I would like to implement the usage of custom formatter.
If you have a hidden column as below, just construct the src
yourself.
{ name: 'customerId', index: 'customerId', hidden: true },
{ name: 'link', index: 'link', title: false,
formatter: function (cellvalue, options, rowObject) {
return '<a href="loadHoldCode/id=?&customerId=' + rowObject.customerId + '" target="_blank">' +
cellvalue + "</a>";
}
}
Upvotes: 2
Reputation: 221997
First of all I want to clear why your original code
formatoptions: {
baseLinkUrl: 'loadHoldCode/id=?',
addParam: '&customerId='+$('#custIdHidden').val()
},
can't work correctly. It means just that formatoptions
property of the corresponding colModel
item should be initialized with object with two properties baseLinkUrl
and addParam
. The value of both properties will be calculated once during the initialization. So you will have $('#custIdHidden').val()
value at the moment of creating the grid.
It would be better to use the construction like
formatoptions: {
baseLinkUrl: 'loadHoldCode/id=?',
addParam: function () {
return '&customerId=' + $('#custIdHidden').val();
}
},
but it will work only if jqGrid would be test whether the value of addParam
is function or not. The formatter "showlink"
don't test any from the options for the function (see the line of jqGrid code). So **you can't use formatter: "showlink"
to implement your requirement.
I would suggest you to use custom formatter (see here the corresponding code example, where $.param
supports properties as functions) or to use formatter: "dynamicLink"
which you can download here (see jqGrid.dynamicLink.js
). It's very simple and very flexible formatter. You can see more details and examples of usage of the formatter here and here.
Upvotes: 0