简体   繁体   English

如何使用链接按钮将JQGrid单元格值传递给Jquery函数

[英]How to Pass the JQGrid Cell Value to Jquery Function using Link Button

My JQGrid cloumns like, 我的JQGrid柱状图

    colNames: ['Job ID', 'MailId','Save'],
    colModel: [
                { name: 'JobId', index: 'JobId', width: 120, align: 'left', editable: true },
                { name: 'MailId', index: 'MailId', width: 150, align: 'left', editable: true },

                {
                    name: 'Save', index: 'Save', width: 100, sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a href='#' id="saveLinkId">Save</a>";

                    }
                }

I create the Save link button at the end of JQGrid cell. 我在JQGrid单元的末尾创建“保存链接”按钮。

I need to pass clicked row's JobId and MailID to jquery function when click the link button in a row.How to do this? 单击行中的链接按钮时,需要将单击的行的JobId和MailID传递给jquery函数 。如何执行此操作?

In the above example you have given, the rowObject parameter in the formatter function will hold all the values in that row. 在上面给出的示例中,formatter函数中的rowObject参数将保存该行中的所有值。 So can use rowObject.JobId for your JobId and rowObject.MailId for your MailId. 因此可以将rowObject.JobId用作JobId,将rowObject.MailId用作MailId。

I would recommend you to use beforeSelectRow (or onCellSelect ) to detect click on <a> in the "Save" column. 我会建议你使用beforeSelectRow (或onCellSelect )来检测点击<a>"Save"栏。 The answer explains what you can do. 答案说明了您可以做什么。 Another answers: this one and this one could be also interesting for you. 另一个答案: 这个这个可能对您也很有趣。

In your case beforeSelectRow could looks like below 就您而言, beforeSelectRow可能如下所示

beforeSelectRow: function (rowid, e) {
    var $self = $(this),
        iCol = $.jgrid.getCellIndex($(e.target).closest("td")[0]),
        cm = $self.jqGrid("getGridParam", "colModel");
    if (cm[iCol].name !== "Save") {
        return true;
    }

    alert ($self.jqGrid("getCell", rowid, "JobId"));
    return false;
}

Additionally you should consider which value you use as id in the input data. 另外,您应该考虑在输入数据中使用哪个值作为id The value build so name rowid - the value of id attributes of <tr> elements (the rows of the grid). 该值构建为name rowid- <tr>元素(网格的行)的id属性的值。 If for example either JobId or MailId (one from the two columns) contains unique values for every row then you can use the value from the column as the rowid. 例如,如果JobIdMailId (两列中的一个)包含每一行的唯一值,则可以将列中的值用作行ID。 To do this you need just add key: true to the corresponding column. 为此,您只需在相应的列中添加key: true即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM