Simon Ryan
Simon Ryan

Reputation: 212

How to dynmically make a cell editable in jqGrid MVC version

I thought I could use the event gridInitialized an run loop through the id's of each row adding the class 'non-editable-cell' but the class is added but when the row is put into edit mode the cells with the class are still editable.

function gridInitialized() { var grid = jQuery('#enabledLanguagesGrid'); 
    var ids = grid.getDataIDs(); 
    for(var i = 0; i < ids.length; i++)  
        var id = ids[i]; 
        if (grid.getCell(id, 'isCustom') === 'True') {
            grid.setCell(id, 'name', '', 'not-editable-cell')
        } 
    } 
}

When I use grid.editRow to enter edit mode the name field is still editable.

On another note, I am not receiving any replies on the trirand.net public forum or on the support email address. It's been 8 days since my first contact with them. Anybody else experiencing problems with support at Trirand?

Many thanks

Upvotes: 0

Views: 484

Answers (1)

Oleg
Oleg

Reputation: 221997

Please include in all your question the information about the version of jqGrid, which you use (can use), and about the fork (free jqGrid, commercial Guriddo jqGrid JS or an old jqGrid in version <=4.7).

It's important to understand, that jqGrid has 3 alternative editing modes: inline editing, form editing and cell editing. The class not-editable-cell will be used only by cell editing. You wrote about the editRow, which is part of inline editing. It supports``not-editable-row` class, which can be set on rows to prevent the whole row be editable.

The implementation of your requirements heavy depend on your exact requirements and on the version of jqGrid, which you use. The most easy solution exist if you use free jqGrid fork, which I develop starting with the end of 2014 (after making the main fork commercial and renaming it to Guriddo jqGrid JS). Free jqGrid allows to define editable property of the column as callback function. The feature is described in the wiki article. The callback function has rowid as the parameter and one can get the data of the row, analyse the data and to return true/false (allow or not allow to edit the cell) depend on any custom criteria. The editable property as callback is implemented for all editing modes.

If you have to use old version of jqGrid then you should follow the solution described in the old answer or in this one. You can implement the solution in easy way only if you call editRow directly. The solution for indirect usage of editRow (by inlineNav or formatter: "actions") is much more complex.

The final remark. You should try never use the code like gridInitialized, which you posted, because it modifies the data on the page in the loop. It's important to understand, that modifying of one element on HTML page follows web browser reflow. The web browser have to recalculate or to change the position or other properties of all existing elements on the page. Thus you essentially increase the complexity of the code and reduce the performance of your page if you modify elements on the page. I'd recommend you to read the old article and to use cellattr, rowattr and custom formatters instead of changing the data in the loop.

Upvotes: 1

Related Questions