0

I have a jqgrid populated by some fields. I want some of the cells to be

editable:true 

or

editable:false 

based on a condition

Here's my function (EDITED):

var grid = $("#mygrid"); var getColumnIndexByName = function(gr,columnName) { var cm = gr.jqGrid('getGridParam','colModel'); for (var i=0,l=cm.length; i<l; i++) { if (cm[i].name===columnName) { return i; // return the index } } return -1; }; function abilitaDisabilitaEditRecord() { var pos=getColumnIndexByName(grid,'descrizione'); var pos2=getColumnIndexByName(grid,'endDate'); var allIds = $('#mygrid').jqGrid('getDataIDs'); var cells = $("tbody > tr.jqgrow > td:nth-child("+(pos+1)+")",grid[0]); var cells2 = $("tbody > tr.jqgrow > td:nth-child("+(pos2+1)+")",grid[0]); for (var i = 0; i < allIds.length; i++) { for (var j=0; j<cells.length; j++) { var cell = $(cells[j]); var cell2 = $(cells2[j]); var checkDataFine = $('#mygrid').jqGrid('getCell', allIds[i], 'date'); if (!checkDataFine==false) { cell.addClass('not-editable-cell'); cell2.addClass('not-editable-cell'); } } } } 

2 Answers 2

0

you can call this in you else condition, i didn't test it, but i think this should work

$("#mygrid").jqGrid('restoreRow',allIds[i]);

Sign up to request clarification or add additional context in comments.

6 Comments

that's about a single cell attribute, not a row attribute
oh sorry you want to disable only cell editing...here you go buddy ...this answer will help you stackoverflow.com/questions/5092571/…
the problem was I need to disable the entire row if one cell of the row contains somethin, this example is fine to single cell
so buddy the earlier solution $("#mygrid").jqGrid('restoreRow',allIds[i]); will restore the entire row...did you try something or you are just assuming things here?
post some code with the usage of retoreRow and lets figure out why its not restoring the entire row, cause the functionality of restoreRow is to restore the entire row
|
0

Here's the working solution:

var grid = $("#mygrid"); var getColumnIndexByName = function(gr,columnName) { var cm = gr.jqGrid('getGridParam','colModel'); for (var i=0,l=cm.length; i<l; i++) { if (cm[i].name===columnName) { return i; } } return -1; }; function changeEditableByContain() { var pos=getColumnIndexByName(grid,'field1'); var pos2=getColumnIndexByName(grid,'field2'); var pos3=getColumnIndexByName(grid,'field3'); var pos4=getColumnIndexByName(grid,'field4'); var allIds = $('#mygrid').jqGrid('getDataIDs'); var cells = $("tbody > tr.jqgrow > td:nth-child("+(pos+1)+")",grid[0]); var cells2 = $("tbody > tr.jqgrow > td:nth-child("+(pos2+1)+")",grid[0]); var cells3 = $("tbody > tr.jqgrow > td:nth-child("+(pos3+1)+")",grid[0]); var cells4 = $("tbody > tr.jqgrow > td:nth-child("+(pos4+1)+")",grid[0]); for (var i = 0; i < allIds.length; i++) { var cell = $(cells[i]); var cell2 = $(cells2[i]); var cell3 = $(cells3[i]); var cell4 = $(cells4[i]); if (condition...) { cell.addClass('editable-cell'); cell2.addClass('editable-cell'); cell3.addClass('editable-cell'); cell4.addClass('editable-cell'); } else{ cell.addClass('not-editable-cell'); cell2.addClass('not-editable-cell'); cell3.addClass('not-editable-cell'); cell4.addClass('not-editable-cell'); } } } 

and then call onloadcomplete:

changeEditableByContain(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.