2017-01-11 1 views
2

첫 번째 열에 하이퍼 링크 인 숫자가있는 jqgrid가 있습니다. 클릭하면 나는 formatter:linkfmatter을 사용하고 ajax 호출을 사용하여 백엔드에 rowid를 보냅니다. 열 B 0 내가 열 A 하이퍼 링크되고 싶어하지만 특정 행의 열 B 1 때 내가 비활성화 된 열 B 하이퍼 링크를 원하는 경우다른 열 값을 기반으로 jqgrid에서 하이퍼 링크를 사용하지 않음

지금 내 요구 사항입니다.

누군가가 가능하면 javascript-jquery를 사용하여 올바른 방향으로 나를 가리킬 수 있습니까? 는 여기에있는 jqGrid

$("#tblJQGridCCVT").jqGrid({ 
    url: "@Url.Action("MyAction", "MyController")" + "?Parameters=" + Params + "", 
    datatype: "json", 
    mtype: 'GET', 
    cache: false, 
    async: false, 
    colNames: ['A', 'B', 'C', 'D', 'E','F', so on...],//nearly 30 columns 
    colModel: [ 
     { name: 'A', index: 'A', width: 150, edittype: 'select', formatter: linkFmatter }, 
     { name: 'B', index: 'B', width: 150 }, 
     { name: 'C', index: 'C', width: 150 }, 
     { name: 'D', index: 'Updated By', width: 150 }, 
     { name: 'E', index: 'E', width: 150 }, 
     { name: 'F', index: 'F', width: 150 }, 
     So on 
      ... 
      ... 
      ... 
    ], 
    pager: $('#pager'), 
    height:300, 
    rowNum: 10, 
    sortorder: "desc", 
    sortname: 'ResponseId', 
    viewrecords: true, 
    sortable: true, 
    loadonce: true, 
    forceClientSorting: true, 
    ignoreCase: true, 
    caption: "Summary" 
}); 
$("#tblJQGridCCVT").jqGrid('navGrid', '#pager', { view: false, del: false, add: false, edit: false, search: true, refreshtext: "Refresh" }, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true }, {}, {}, {}); 
$("#tblJQGridCCVT").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: 'cn' }); 

function linkFmatter(cellvalue, options, rowObject) { 
    var selectedCellValue = cellvalue; 
    var selectedRowId = options.rowId; 
    return '<a href="javascript:MethodJS(' + selectedRowId + ')" style="color: #3366ff" id="' + selectedRowId + '" >' + selectedCellValue + '</a>'; 
} 


function MethodJS(selectedRowId) { 
    $.ajax({ 
     async: false, 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     url: "@Url.Action("GetDetailedViewOfResponsesForEdit", "ViewResponseDetailsCCVT")", 
     data: "{RowId:'" + selectedRowId + "'}", 
     success: function (Result) { 
      if (Result == "Success") { 
       var url = window.location.href; 
       window.location.href = "@Url.Action("ResponseDetailsEditForCCVT", "ViewResponseDetailsCCVT")"; 
      } 
     } 
    }); 
} 

답변

2

당신은 rowObject 매개 변수에 행 데이터가 내 코드입니다. 다음과 같이 사용할 수 있습니다.

function linkFmatter(cellvalue, options, rowObject) { 
    if (rowObject.B == 0) { 
     var selectedCellValue = cellvalue; 
     var selectedRowId = options.rowId; 
     return '<a href="javascript:MethodJS(' + selectedRowId + ')" style="color: #3366ff" id="' + selectedRowId + '" >' + selectedCellValue + '</a>'; 
    } 

    return cellvalue 
} 

DEMO HERE