包含href链接的网格链接到所有行而不是特定行

时间:2013-04-19 06:10:35

标签: jqgrid

我制作了一个网格,其中最后一列包含重新发送的链接。此链接将邮件重新发送到该行中提到的聚会。当我点击该链接时,它会将邮件重新发送给网格中的所有各方而不是该特定行。下面是我的代码

   $(document).ready(
function(){


   var lastselsignStatusGrid ;
    var signStatusGridurl = $('#signatureStatus_ctxPath').val() +                   '/rest/retrieveSignStatus';
    var maintainsignStatusGridurl = $('#signatureStatus_ctxPath').val() +  '/rest/maintainSignStatus';
  jQuery('#signStatusGrid').jqGrid({
url: signStatusGridurl,
datatype: "json",
mtype: 'GET',
altRows:true,
loadonce: true,
colNames:['Name','Role','Signature status','Due Date','Signed              Date','Email','EmailId','PartyId'],
colModel:[
    {name: 'name',index: 'name',sortable:true,search:true,sorttype: 'text',               searchoptions:{sopt:['eq','ne','bw','cn']}},
{name: 'role',index: 'role',sortable:true,search:true,sorttype: 'text', searchoptions: {sopt:['eq','ne','bw','cn']}},
      {name: 'signed',index: 'signed',sortable:false,search:false,sorttype: 'text'},
 {name: 'dueDate',index: 'dueDate',formatter: 'date', formatoptions:      {"srcformat":"m/d/Y","newformat":"m/d/Y"}, unformat: unformat, sortable:false,search:false,sorttype: 'date'},
   {name: 'signedDate',index: 'signedDate',sortable:false,search:false,sorttype: 'text'},
   {name: 'resend',index: 'resend',formatter: customLinksignStatusresend, unformat: unformat, sortable:false,search:false,sorttype: 'text'},
   {name: 'emailAddress',index: 'emailAddress',hidden:true },
   {name: 'partyId',index: 'partyId',hidden:true}

],
rowNum:10,
rowList:[10,20,30],
multiselect: false,
viewrecords: true,
emptyrecords: "No record present",
imagepath: "js/themes/redmond/images",
autowidth: true,
caption:''
   });

    function customLinksignStatusresend(cellValue, options, rowObject){

if (rowObject[2] == "Complete") { 
    return "";
} else{
    //return rowObject[5];
    //return '<a href="#">' + "Resend</a>";
    return '<a href="#Test">' + cellValue + '<a>';
}
}
    $(document).delegate('#signStatusGrid .jqgrow td a[href="#Test"]', 'click',   function () 
     { 
var localGridData = $("#signStatusGrid").jqGrid('getGridParam','data');
var postData = JSON.stringify(localGridData);
var rowDetails="";
var selectedRows = $('#signStatusGrid').jqGrid('getGridParam', 'data');
var rowsArray = new Array();
var rowId = '';


for(var i=0;i<localGridData.length;i++)
{
     var rowData = localGridData[i];
     var emailAddr = rowData.emailAddress;
     var partyId = rowData.partyId;
    rowDetails += partyId+":" +emailAddr+ ',';

    $.ajax({

    url: $('#signatureStatus_ctxPath').val()+'/rest/resendEmail?partyId='+ partyId,

                datatype : "json",
                contentType: "application/json; charset=utf-8",
                type:"POST",
                error : function(xhr, textStatus, errorThrown) {
                    alert(errorThrown);
                },
                success : function(response, textStatus, xhr) {
                    alert("email resent successfully");
                }

            });

     HideLayer();
    }
    });

1 个答案:

答案 0 :(得分:0)

您正在遍历网格中的所有行,这就是将邮件发送给所有收件人的原因。


执行您要实现的目标的简单方法是使用jqGrid的onCellSelect函数将邮件发送到特定的Row emailId。您可以添加其他条件,以便仅在单击链接时调用它。

onCellSelect: function (id, iCol, cellContent, e) {
    if (iCol == 'resend') {
        var emailAddr = $('#signStatusGrid').getCell(id, 'emailAddress');
        var partyId = $('#signStatusGrid').getCell(id, 'partyId');
        var rowDetails += partyId + ":" + emailAddr + ',';
        $.ajax({

            url: $('#signatureStatus_ctxPath').val() + '/rest/resendEmail?partyId=' + partyId,

            datatype: "json",
            contentType: "application/json; charset=utf-8",
            type: "POST",
            error: function (xhr, textStatus, errorThrown) {
                alert(errorThrown);
            },
            success: function (response, textStatus, xhr) {
                alert("email resent successfully");
            }

        });
    }
},

另一个替代解决方案似乎是创建一个发送邮件的功能,并设置一个链接,该链接将使用jqGrid的gridComplete函数中的相应partyId调用相同的内容:

gridComplete: function () {
    var ids = jQuery("#signStatusGrid").jqGrid('getDataIDs');
    for (var i = 0; i < ids.length; i++) {
        var cl = ids[i];
        var partyId = $('#signStatusGrid').getCell(ids[i], 'partyId');
        var be = "<a href='#Test' onclick='sendMail(" + partyId + ");' >View Contract</a>";
        jQuery("#signStatusGrid").jqGrid('setRowData', ids[i], {
            editct: be
        });
    }
},



var sendMail(partyId) {
    $.ajax({

        url: $('#signatureStatus_ctxPath').val() + '/rest/resendEmail?partyId=' + partyId,

        datatype: "json",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        error: function (xhr, textStatus, errorThrown) {
            alert(errorThrown);
        },
        success: function (response, textStatus, xhr) {
            alert("email resent successfully");
        }

    });
}