0

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
user2375298
  • 1,001
  • 4
  • 15
  • 28

2 Answers2

2

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>";
    }
}
Wilts C
  • 1,720
  • 1
  • 21
  • 28
0

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi Oleg, if i have to add a param that is part of a jqgrid row? is it possible then? – user2375298 Feb 12 '15 at 10:09
  • @user2375298: It's possible of cause and I suggested you some implementation options. If you want to use custom formatter, then the implementation should corresponds the **input data of the grid** which you use. You used `$('#custIdHidden').val()` in the original code. It meas that you wanted to place **the same value** in all cells of the columns. The value `rowObject.customerId` means that you have `customerId` property in every input item. So it means different values for every row. Moreover if you use `rowObject.customerId` and not `rowObject[12]` or some other syntax. It should be in data – Oleg Feb 12 '15 at 10:54
  • @user2375298: Which format have input data from the grid? Could you provide test data (at least one row). If the format of data corresponds the usage of `jsonReader: {repeatitems: true}` or `xmlReader: {repeatitems: true}` then the syntax `rowObject.customerId` will be wrong. Which `datatype` you use ("json", "xml", "local", ...)? Do you use `loadonce: true` (in case of usage `datatype: "json"` or `datatype: "xml"`) or not? Which version of jqGrid you use? – Oleg Feb 12 '15 at 10:58
  • I am using loadonce =true, and I am using Json Data. I am using a custom formatter function and When I try to access the value from rowdata, I get undefined . – user2375298 Feb 12 '15 at 11:27
  • @user2375298: **Which version of jqGrid you use? Which format have input data from the grid? Could you provide test data (at least one row).** `{"rows": [["a","b",123, null, true],...]}` are JSON data and `["rows": [{"customerId": "a", "col2": "b", "col3": 123, "col4": null, "col1": true}, ...]` are JSON data too, but the data should be read in different way. – Oleg Feb 12 '15 at 11:45