开发者

jqgrid column linq with ASP.NET MVC

开发者 https://www.devze.com 2023-03-29 20:36 出处:网络
I have a class 开发者_JAVA百科(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.000

I have a class 开发者_JAVA百科(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"}
]


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消