TheBoubou
TheBoubou

Reputation: 19933

jqgrid column linq with ASP.NET MVC

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"}
]

Upvotes: 2

Views: 915

Answers (1)

Oleg
Oleg

Reputation: 221997

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.

Upvotes: 1

Related Questions