2017-02-04 122 views
2

在网格内部,在'批准/拒绝'列OnRowCommand中有一个ID为'txtRemarksByEntity'的文本框,我需要检索文本框的值。如何获取文本输入字段的值?

function BtnProcurementApprovalByEntityClick(rowId, value) { 
    var rowData = $('#GridProcureApprovalByEntity').getRowData(rowId); 
    ReqIdApproval = rowData['RequestId']; 
    ApprovalEntityId = rowData['approvalentityid']; 
    ApprovalTypeId = rowData['approvaltypeid']; 
    ApprovalStatusText = rowData['status_desc']; 
    var ab = rowData["Approve/Reject"]; 
    var $str1 = $(ab); 
    alert($str1.val()); 
} 

在rowData变量,我得到

Approval_Type:"Oprations" 
Approve/Reject:"Remarks  <input type="text" id="txtRemarksByEntity" class="txtRemarksByEntity" style="width: 250px">  <img src="images/yes1.PNG" style="cursor:pointer;" onclick="BtnProcurementApprovalByEntityClick(5 , 1)">  <img src="images/cross1.PNG" style="cursor:pointer;" onclick="BtnProcurementApprovalByEntityClick(5 , 2)">" 
RequestId:"51213" 
Request_Id:"PR51213" 
SrNo:"5" 
approvalentityid:"2234" 
approvaltypeid:"2" 
status_desc:"<span style="color:#EAA66A"><b>Pending</b></span>" 
statusid:"0" 
undefined:"<button type="button" class="button edit" onclick="editProcureApprovalByEntity(5)">Edit</button>" 

我动态结合电网如下

$("#GridProcureApprovalByEntity").jqGrid({ 
    autowidth: true, 
    height: 'auto', 
    shrinkToFit: true, 
    data: arr, 
    datatype: "local", 
    colNames: ['SrNo', 'PR No.', 'Approval Type', 'Approval Status', 'statusid', 'approvaltypeid', 'Approve/Reject', '', 'approvalentityid', 'RequestId'], 
    colModel: [{ 
     name: 'SrNo', 
     index: 'SrNo', 
     width: 30, 
     align: 'center' 
    }, { 
     name: 'Request_Id', 
     index: 'Request_Id', 
     width: 50, 
     align: 'center' 
    }, 
    { 
     name: 'Approval_Type', 
     index: 'Approval_Type', 
     width: 100, 
     align: 'center' 
    }, { 
     name: 'status_desc', 
     index: 'Approval Status', 
     width: 80, 
     align: 'center', 
     formatter: ApprovalFormatter 
    }, { 
     name: 'statusid', 
     index: 'statusid', 
     width: 0, 
     hidden: true 
    }, { 
     name: 'approvaltypeid', 
     index: 'approvaltypeid', 
     width: 0, 
     hidden: true 
    }, 
    //{ 
    //   align:'center', 
    //   formatter: function (cellvalue, options, rowobject) { 
    //    return '<button type="button" class="button edit" onClick="editProcureApproval(' + options.rowId + ')">Edit</button>'; 
    //   } 
    //  }, 

    { 
     name: 'Approve/Reject', 
     index: 'Approve/Reject', 
     formatter: formateeApprovalByEntity, width: 250, 
     align: 'center' 
     }, 
    { 
     formatter: formateApprovalByEntity, width: 50 
    }, 
    { 
     name: 'approvalentityid', 
     index: 'approvalentityid', 
     width: 0, 
     hidden: true 
    }, 
    { 
     name: 'RequestId', 
     index: 'RequestId', 
     width: 0, 
     hidden: true 
    } 

    ], 
    pager: "#PagingGridProcureApprovalByEntity", 
    rowNum: 10, 
    //rowList: [1, 2, 3], 
    //sortname: "Sno", 
    //sortorder: "desc", 
    viewrecords: true, 
    gridview: true, 
    autoencode: true, 
    hoverrows: false, 
    gridComplete: function() { 
     var recs = $("#GridProcureApprovalByEntity").getGridParam("reccount"); // parseInt($("#GridApproval").getGridParam("records")); 
     if (isNaN(recs) || recs == 0) { 
      $("#dvProcureAppGridByEntity").hide(); 
     } 
    }, 
    ondblClickRow: function (rowId) { 

    }, 
    loadComplete: function() { 
     $("tr.jqgrow:odd").css("background", "#EEF7FB"); 
    } 
    //,  caption: "Approval Details" 
}).jqGrid("navGrid", "#PagingGridProcureApprovalByEntity", { 
    search: false, 
    edit: false, 
    add: false, 
    del: false, 
    refreshstate: "current" 
}); 



function formateeApprovalByEntity(cellvalue, options, rowobject) { 
var str = ''; 
if (rowobject.statusid == "0") { 
    str = 'Remarks  <input type="text" id="txtRemarksByEntity" class="txtRemarksByEntity" style= "width: 250px"/>' + '  ' + 
     '<img src="images/yes1.PNG" style="cursor:pointer;" onClick="BtnProcurementApprovalByEntityClick(' + options.rowId + ' , ' + 1 + ')"/>' + '  ' + 
     '<img src="images/cross1.PNG" style="cursor:pointer;" onClick="BtnProcurementApprovalByEntityClick(' + options.rowId + ' , ' + 2 + ')"/>' 
} 
else { 
    str = ''; 
} 
return str; 
} 

$ str1.val()始终是 “”

回答

1

的jqGrid的代码包含许多部分,这是不正确的,但问题的主要原因,你问是使用而不指定相应的unformatter。你应该定义unformat回调,其中得到来自单元格的数据。如果我没有理解你的代码,那么你可以使用,例如,

unformat: function (cellvalue, options, cell) { 
    return $(cell).find(".txtRemarksByEntity").val(); 
} 

其他一些错误:

  • 一个永远不应该使用相同的静态值,以自定义格式的内部的任何元素分配id。它产生id复制品。例如,您应该从formateeApprovalByEntity格式化程序中删除id="txtRemarksByEntity"
  • name每列colModel的值应该对应HTML中的id的要求。在name内使用特殊字符是不好的。例如,我建议将name: 'Approve/Reject'更改为name: 'Approve_Reject'。以同样的方式,列{ formatter: formateApprovalByEntity, width: 50 }是错误的。这是undefinedrowData的来源。您必须为列指定一些非空的name值,例如name: "approval"
  • colModel中指定index属性很不好,尤其是在您使用datatype: "local"时。通过复制name属性的值自动生成默认值indexname: 'status_desc'列中的值index: 'Approval Status'可以防止按列进行排序和搜索。我建议你从colModel

删除所有index特性最后我会问你指定的jqGrid的版本,您使用的(可以使用),并jqGrid的的叉(free jqGrid,商业Guriddo jqGrid JS或版本< = 4.7中的旧jqGrid),您使用的是,每个问题关于jqGrid。我开发免费的jqGrid分叉,我可以推荐你使用。您可以直接从CDN加载它(请参阅the wiki article)。

0

您需要委派和使用数据属性

if (rowobject.statusid == "0") { 
    str = 'Remarks  <input type="text" id="txtRemarksByEntity" class="txtRemarksByEntity" style= "width: 250px"/>' + '  ' + 
     '<img class="imgRemarksByEntity" src="images/yes1.PNG" style="cursor:pointer;" data-rowID="[' + options.rowId + ' , ' + 1 + ']"/>' + '  ' + 
     '<img class="imgRemarksByEntity" src="images/cross1.PNG" style="cursor:pointer;" data-rowid="[' + options.rowId + ' , ' + 2 + ']"/>' 
} 

,并有

$("#someStaticParentOfImage").on"click",".imgRemarksByEntity",function() { 
    var rowId=$(this).data("rowid"); 
    BtnProcurementApprovalByEntityClick(rowId[0],rowId[1]); 
}); 

另外的ID必须是唯一的

+0

ID是唯一的,我得到的所有列值都与RowID相关,但txtRemarksByEntity值始终为空。 – Soniya