JqG​​rid需要超链接-需要通过Jquery捕获值 [英] JqGrid need hyperlink - need to capture value through Jquery

查看:97
本文介绍了JqG​​rid需要超链接-需要通过Jquery捕获值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中包含以下内容:

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

如果链接的生成方式如下

In the case the links will be generated like

<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>,它像链接一样寻找用户.您可以使用beforeSelectRowonCellSelect回调在单元格上捕获click事件.例如

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;
    }
}

如果需要,您可以使用getColgetRowData从单击的行中获取任何其他数据,并将该信息附加到目标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.

这篇关于JqG​​rid需要超链接-需要通过Jquery捕获值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆