问题描述
我的代码中有以下内容:
I have the following in my code:
{ name: 'ID', index: 'ID', width: 40 , formatter: 'showlink', search: false, formatoptions: { baseLinkUrl: '/Program/EditMicro'} },
当我点击 PNum 时,会发生以下情况:我的控制器会执行以下操作:
When I click on the PNum, what happens is that it goes to the following actionresult my controller:
/Program/EditMicro
我想要的是通过 Jquery 捕获有关所选内容的信息(选择了什么 ID)因为我想在将它发送到以下 ActionResult 之前做一些 json
What I would like instead is to capture that info through Jquery on what was selected (what ID was selected)as I want to do some json before it is sent to the following ActionResult
/Program/EditMicro
所以,回顾一下,是否有捕获超链接点击的值是什么,然后我可以在 Jquery 中捕获它.
So, to recap, is there anyway to capture what the value of the hyperlink clicks on is and then I can capture that in Jquery.
提前谢谢你
推荐答案
在大多数情况下,使用类似的东西就足够了
In the most cases it's enough to use something like
formatter: "showlink",
formatoptions: {
baseLinkUrl: "/Program/",
showAction: "EditMicro",
idName: "myId"
}
如果链接会像这样生成
<a href="/Program/EditMicro?myId=123">text from the cell</a>
如果您在操作中有行的 id,您可以直接从数据库中获取您需要的任何其他附加信息.
If you have in the action the id of the row you can get any other additional information which you need directly from the database.
或者,您可以使用答案中描述的简单技巧.你定义 CSS 类
Alternatively you can use the simple trick described in the answer. You define CSS class
.myLink { text-decoration: underline; cursor: pointer; }
然后您可以使用如下自定义格式化程序
Then you can use custom formatter like below
formatter: function (cellValue, options, rowObject) {
return "<span class='myLink'>" + cellValue + "</span>";
},
cellattr: function () {
return " title="Click here to go to EditMicro"";
}
以您将生成 <span>
的方式,它会像链接一样寻找用户.您可以使用 beforeSelectRow
或 onCellSelect
回调捕获单元格上的单击事件.例如
In the way you will generate <span>
which look for the user like a link. You can catch the click event on the cell using beforeSelectRow
or onCellSelect
callback. For example
beforeSelectRow: function (rowid, e) {
var $td = $(e.target).closest("td"),
iCol = $.jgrid.getCellIndex($td[0]);
if (this.p.colModel[iCol].name === 'note') {
window.location = "/Program/EditMicro/" +
encodeURIComponent(rowid);
return false;
}
}
如果需要,您可以使用 getCol
或 getRowData
从单击的行中获取任何其他数据并将信息附加到目标 URL.
If needed you can use getCol
or getRowData
to get any other data from the clicked row and append the information to the target URL.
这篇关于JqGrid 需要超链接 - 需要通过 Jquery 捕获价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!