首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jqGrid celledit将单元格设置为只读动态

jqGrid celledit将单元格设置为只读动态
EN

Stack Overflow用户
提问于 2014-02-07 14:25:59
回答 1查看 2.2K关注 0票数 0

我在用赛勒迪特。我有一个包含编辑类型textarea的专栏。我希望根据同一行中的另一个单元格值动态地读取textarea。

如何将特定的单元格设置为只读?有类似于“.addClass(不可编辑的-单元格”)的东西吗?

谢谢你提前帮忙。

更新:我刚刚找到了一种方法。

代码语言:javascript
复制
In the formatcell Event:
if (iRow = 4) {
$(grid).setColProp('note', { editoptions: { readonly:true} });
}

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-11 05:03:13

调用textReadyOnly函数在colModel of stateCode中创建列readOnly=true。根据条件制作了textarea readOnly = true/false

代码:

代码语言:javascript
复制
$(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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21630209

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档