jqgrid在网格加载后将单元格输入更改为只读

时间:2011-03-15 12:35:15

标签: jqgrid

如何在加载所有网格数据后将单元格输入更改为“只读”?

我只希望加载的行将此单元格作为只读,当我添加新行时,我不希望此单元格是只读的。

感谢提前。

更新

这是我的代码:

$("#Grid1").jqGrid(
        {
            editurl: "clientArray",
            datatype: 'xmlstring',
            datastr: '<%=_xml_string %>' ,
            colNames:['','cell1','cell2', 'cell3'],
            colModel:[
                                        {name:'cell1',index:'cell1', hidden: true},
                                        {name:'cell2',index:'cell2', width:150, editable:true, edittype:'text',sorttype:"int" ,
                                            editoptions:
                                            {                                               
                                                maxlength:5,
                                                dataInit: function (elem)
                                                {
                                                    $(elem).numeric(false);

                                                    $(elem).blur(function(event_)
                                                    {

                                                    });
                                                },
                                              dataEvents:
                                              [
                                                {
                                                    type: 'keydown',
                                                    fn: function(e)
                                                    {
                                                        var key = e.charCode || e.keyCode;
                                                        if(key == 113)
                                                        {
                                                        }
                                                    }
                                                }
                                            ]
                                            }                                                
                                        },
                                        {name:'cell3',index:'cell3', width:150 , editable:true,sorttype:"text" ,
                                          editoptions:
                                          {
                                            readonly: 'readonly' ,
                                            dataInit: function (elem)
                                            {
                                                  $(elem).attr("tabindex","-1");                                                      
                                            }                                                
                                          }
                                        }
                                  ],
            height: '120px' ,
            autowidth: true,
            shrinkToFit: false,

            beforeSelectRow: function(rowid, e)
            {
               if (required_field != rowid && required_field!="")  return false;
                else
                {
                    if( $(this).getGridParam('selrow') == rowid)
                        return false;
                    else
                        return true;
                }
            },
            onSelectRow: function(id)
            {                                        
                save_row(lastSel);
                get_grid().editRow(id,false,'','','','','','','');
                jQuery ('#' + id + _cell2').focus();
                lastSel=id;                    
            },
            loadComplete: function()
            {
                var grid = $("#Grid1");
                var ids = grid.jqGrid('getDataIDs');
                for (var i=0;i<ids.length;i++)
                {
                    var id_=ids[i];alert(id_);
                    grid.jqGrid('setCell',id_,'cell2','','not-editable-cell');
                }
            }
          });              

1 个答案:

答案 0 :(得分:3)

如果使用某种编辑模式编辑网格,则可以在单元格上设置“not-editable-cell”或在行上设置“not-editable-row”以防止单元格或行可编辑。有关代码示例,请参阅this answer