2014-02-07 61 views
0

我正在使用celledit。我有一個editype textarea的專欄。 我想基於同一行中的另一個單元格值使textarea動態只讀。jqGrid celledit將cell設置爲只讀動態

我如何設置特定的單元格爲只讀?是否有類似「.addClass('not-editable-cell')」的東西?

感謝您的幫助提前。

更新: 我剛纔已經找到了一種方法。

In the formatcell Event: 
if (iRow = 4) { 
$(grid).setColProp('note', { editoptions: { readonly:true} }); 
} 

in the restorecell Event: 
$(grid).setColProp('note', { editoptions: { readonly:false} }); 

回答

0

呼叫textReadyOnly功能列stateCode爲使列readOnly=truecolModel。基於條件,它使得textarea readOnly = true/false

代碼:

$(document).ready(function(){ 
    //jqGrid 
    $("#statesList").jqGrid({ 
     url:'<%=request.getContextPath()%>/Admin/getAllStatesList', 
     datatype: "json",    
     colNames:['Edit','State Code','State Name','Country Name', 'Country Code','Active'], 
     colModel:[ 
      {name:'stateId', index:'stateId',search:false, width:30,sortable: false, formatter: editLink}, 
      {name:'stateCode',index:'stateCode', width:100, formatter:textReadOnly}, 
      {name:'stateName',index:'stateName',width:200}, 
      {name:'countryName',index:'country.countryName', width:200}, 
      {name:'countryCode',index:'country.countryCode', width:100}, 
      {name:'isActive',index:'isActive',width:80}, 
      ], 
      rowNum:20, 
      rowList:[10,20,30,40,50], 
      rownumbers: true, 
      pager: '#pagerDiv', 
      sortname: 'stateCode', 
      viewrecords: true, 
      sortorder: "asc", 
      autowidth:'true', 
    }); 
    $('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%"); 
    $('.ui-jqgrid-bdiv').css('height', window.innerHeight * .65); 
    $('#load_statesList').width("130"); 
    $("#statesList").jqGrid('navGrid','#pagerDiv',{edit:false,add:false,del:false}); 
    $(".inline").colorbox({inline:true, width:"20%"}); 
}); 
function editLink(cellValue, options, rowdata, action) { 
     return "<a href='<%=request.getContextPath()%>/Admin/addState/" 
    + rowdata.stateId + "' class='ui-icon ui-icon-pencil' ></a>"; 
} 
function textReadOnly(cellValue, options, rowdata, action) { 
    if (rowdata.stateId == 4) { 
     return "<input value='"+ rowdata.stateId +"' readonly='true'></input>"; 
    } else { 
     return "<input value='"+ rowdata.stateId +"'></input>"; 
    } 
} 
+0

謝謝您的回答! – user3229474

+0

@ user3229474不客氣。 – pudaykiran