2

I have a class (Person) with 4 properties : Id, FirstName, LastName, Code.

I show a person list in a jqgrid. I'd like a link column with this format (the code has this format 2011.0001)

/Person/Detail/Code => /Person/Code/2011.0001

But I have this with the code below : /Customer/Detail?Code=2

I tried this :

colModel: [
    { name: 'Code', index: 'Code', formatter: 'showlink', formatoptions: { baseLinkUrl: '/Customer/Detail', idName: 'Code' }},
    { name: 'LastName', index: 'LastName', align: 'left' },
    { name: 'FirstName', index: 'FirstName', align: 'left' }                  
],

How can I correct this ?

Thanks,

Update1, Data format

[
{"Id":1,"FirstName":"AAAA","LastName":"AA","Code":"2011.0001"},
{"Id":3,"FirstName":"BBBB","LastName":"BB","Code":"2011.0003"}
]
TheBoubou
  • 19,487
  • 54
  • 148
  • 236
  • Could you post the test data which you use to fill the grid? Are the values from the `Code` unique? Could be probably the column be used as the `id` for the grid rows? – Oleg Aug 21 '11 at 14:02
  • See update1. Code is unique yes, there is an a technical id but I'd like the controller receive the code value. – TheBoubou Aug 21 '11 at 14:15
  • If you need to have the URL in the form `/Person/Code/2011.0001` and not for example in the form `/Person?Code=2011.0001` having URL parameters you should use custom formatter. See my modified answer. – Oleg Aug 21 '11 at 18:03

1 Answers1

1

You can try to use the custom formatter in the form

formatter: function (cellvalue, options, rowObject) {
    return '<a href="/Person/Code/' + rowObject.Code + '">' + cellvalue + '</a>';
}

instead of predefined formatter 'showlink':

formatter: 'showlink', formatoptions: {baseLinkUrl:'/Customer/Detail', idName:'Code'}

You can easy receive /Customer/Detail?Code=2011.0001 if you have unique data in the 'Code' column and if you would add key: true to the column definition. In the case the Id value from the JSON input will be ignored and the value from the 'Code' column will be used as the rowid. If you do need to have the href value in the form /Customer/Detail/Code/2011.0001 or instead of /Customer/Detail?Code=2011.0001 you will need use custom formatter as I described before.

Oleg
  • 220,925
  • 34
  • 403
  • 798