2

how can i change cell input to "readonly" after i loaded all grid's data?

I want only the loaded rows to have this cell as readonly , when i add new rows i don't want this cell to be readonly.

Thank's In Advance.

UPDATE:

this is my code:

$("#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');
                }
            }
          });              
user590586
  • 2,960
  • 16
  • 63
  • 96

1 Answers1

3

If you use some editing mode to edit the grid you can set any time 'not-editable-cell' on the cell or 'not-editable-row' on the row to prevent the cell or the row be editable. See this answer for the code example.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg: thank's! but for some reason that's not working for me.. I'm using editurl: "clientArray",datatype: 'xmlstring',datastr: '<%=_xml_string %>' , and inside the dataInit: function (elem) i have $(elem).numeric(false);. I added exactly what you wrote in the example.. any ideas? – user590586 Mar 15 '11 at 13:11
  • @user590586: I tried to use `$(elem).numeric(false);` inside of `dataInit` and all worked perfect in my code. If I add 'not-editable-row' class to some rows they are not editable. I don't understand which cells you want make "readonly". Probably you should just post the HTML code for the "readonly" cell which you want to have and I show how the code can be placed inside of jqGrid cell. – Oleg Mar 15 '11 at 14:55
  • @Oleg: I really appritiate your help!! I've updated my question with the curretn code. – user590586 Mar 15 '11 at 16:32
  • @user590586: In the code you use 'not-editable-cell' which work **only in the cell editing mode**.The code have syntax error `jQuery ('#' + id + _cell2').focus();` must be `jQuery ('#' + id + '_cell2').focus();`. Moreover I don't understand what work incorrect in the code. Is 'cell3' column not readonly or `numeric` not work? What is wrong and what you you want to implement? – Oleg Mar 15 '11 at 17:01
  • @Oleg: jQuery ('#' + id + _cell2').focus(); is by mistake , i copied it wrong. and i want only cell2 to be not editable , and it does not work for me.. could it be because of the inline editting? what could get it not to work? i don't get an error , it's just keeps being in edit mode.. – user590586 Mar 15 '11 at 17:06
  • @user590586: What jqGrid mean under "non-editable" is the `editable:false`. In another my answer I gives you the reference to [this](http://stackoverflow.com/questions/4307147/jqgrid-how-to-make-a-column-editable-in-the-add-dialog-but-not-during-inline-e/4308172#4308172) which described how one can change `editable:false` dynamically, but you want some other behavior and probably not dynamically, but for the whole column. Which behavior you need? – Oleg Mar 15 '11 at 17:18
  • @Oleg:I saw this answer in my other question. I will explain myself:I'm loading some data from the server to my grid. after the load is completed i want to block from the user certin cells inside my grid,so he wont be able to change them. on the other hand i still want these cells to be edit mode,and not blocked when the user added a new row , or updates a row that just been added.I don't mind which way to do it , just for it to work..at first i wanted the loaded cells to be shown as readonly and not blocked, but if it is not posiible the block is o.k.. did you understand what i want? thanks! – user590586 Mar 15 '11 at 17:40
  • @user590586: OK! What is opened for me: how you allow user to add new rows? Do you use navigator or call `jQuery("#grid_id").editGridRow( "new", properties);` somewhere, or use `addRowData`? – Oleg Mar 15 '11 at 17:52
  • @Oleg: I'm using addRowData (i'm calling it when i "tab" the last cell in a row).. do you need more information? – user590586 Mar 16 '11 at 07:56
  • 1
    @user590586: what you can do is for example following. You can set `editable:false` or no value for `editable` in the `colModel`. So the grid will be non-editable. Then you can hold ids of all rows which user added `addRowData` in an array. In the `onSelectRow` you can test wither the rowid of selected row is in the array of previous added rows. If the rowid not in the array you don't call `editRow` and just return. If the rowid is the id of the previous added row you set temporary `editable:true` in all columns where it needed call `editRow` and change `editable` back to `false`. It will work – Oleg Mar 16 '11 at 09:23
  • @Oleg: I tested it and it works! finally! only i did it by checking a hidden cell inside each row which hold a value if the row is new or from the database. so thank'sss! but i will still be happy to know why 'not-editable-cell' did not work for me? – user590586 Mar 16 '11 at 09:54
  • 2
    @user590586: If you use **cell editing** jqGrid examine cells for the 'not-editable-cell' class. If you use **inline editing** the jqGrid rows for the 'not-editable-row', but in the inline editing mode the 'not-editable-cell' class will be ignored. – Oleg Mar 16 '11 at 10:06
  • @Oleg: i'm almost there..i did in the onSelectRow function: "var _c_edit = _grid.jqGrid('getColProp','code'); , _c_edit.editable = false; " in the rows i want , but now when i try to get the value from this cell i can't .so how can i get a value of an input that is in editable false mode ? thank's. – user590586 Mar 16 '11 at 11:55
  • @Oleg: Is there a way to get a value of an non-editable cell ? or do i have to get it back to editable , get the value , and return it to the non-editable mode? thank's. – user590586 Mar 17 '11 at 12:31
  • @user590586: All non-editable cell are no time in the editable mode, so you can save use [getCell](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods) to get the cell contain. – Oleg Mar 17 '11 at 12:55
  • @user590586: I suppose that I can't help you without have seen the JavaScript code which you use. – Oleg Mar 17 '11 at 20:54