MVC with JQGrid - Having a Link with Multiple Parameters
The Issue with this is that there was not an easy way for me to access other data in the model to create a link with mulitple parameters. In the Jqgrid there are two main ways of creating a link.
The 1st option has very limited parameter support, namely just the id.
The 2nd method based on the documentation and answers in jqgrid and stackoverflow forums, you SHOULD be able to access the rowObject with rowObject.propName. However I cannot use that for some reason that I cannot determine. Accessing other row data by index, or by using a function to determine the index at run time for each column name seems like a maintenance issue waiting to happen.
The other to way to get a hyperlink in the jqgrid as you may be realizing is to pass in Html to the column from the controller. It is an unfortunate choice to make since it breaks the idea of MVC in this case, but I feel that it is better than the alternative. Ideally I would have control of what is going on here, but it does not work out that way here. The data must be split otherwise it would be too much, also I cannot modify stored procedures. There may be a better way of using subgrids or something, but for now I need to get it working, then work on improving it.
3. Html in column
1. Predefined Formatter
{ name: "Detail", index: "Detail", formatter: 'showlink',
formatoptions: { baseLinkUrl: '/GridDetail/Detail' }}
2. Custom Formatter
{ name: "Detail", index: "Detail", formatter: getDetailLink }
then you would have
function getDetailLink(cellvalue, options, rowObject) {
var link = '<a href="/CC/GridDetail' + '/' + rowObject[2] + '">Detail</a>';
return link;
}
The 1st option has very limited parameter support, namely just the id.
The 2nd method based on the documentation and answers in jqgrid and stackoverflow forums, you SHOULD be able to access the rowObject with rowObject.propName. However I cannot use that for some reason that I cannot determine. Accessing other row data by index, or by using a function to determine the index at run time for each column name seems like a maintenance issue waiting to happen.
The other to way to get a hyperlink in the jqgrid as you may be realizing is to pass in Html to the column from the controller. It is an unfortunate choice to make since it breaks the idea of MVC in this case, but I feel that it is better than the alternative. Ideally I would have control of what is going on here, but it does not work out that way here. The data must be split otherwise it would be too much, also I cannot modify stored procedures. There may be a better way of using subgrids or something, but for now I need to get it working, then work on improving it.
3. Html in column
{ name: "Detail", index: "Detail", formatter: "link" }Then in controller you can create the link.
"<a href='" + HttpContext.Request.Url.Scheme + "://" +
HttpContext.Request.Url.Authority + Url.Action("GridDetail", "CC",
new { r.groupId, r.groupName, r.rNId}) + "'>Detail</a>"
Comments
Post a Comment