【问题标题】:jqGrid celledit set cell to readonly dynamicalyjqGrid单元格编辑将单元格设置为动态只读
【发布时间】:2014-02-07 14:25:59
【问题描述】:

我正在使用单元编辑。我有一个带有 editype textarea 的专栏。 我想根据同一行中的另一个单元格值使 textarea 动态只读。

如何将特定单元格设置为只读?有没有类似“.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} });

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    stateCode 列的 colModel 中调用 textReadyOnly 函数以生成 readOnly=true 列。根据条件,它会生成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>";
        }
    }
    

    【讨论】:

    • 感谢您的回答!
    猜你喜欢
    • 2016-07-15
    • 2012-10-19
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    相关资源
    最近更新 更多