jQWidgets Forums
jQuery UI Widgets › Forums › Grid › making some columns editable on cell edit but not others
This topic contains 4 replies, has 2 voices, and was last updated by qtipaddict 11 years, 3 months ago.
-
Author
-
I want to enable editing of specific columns when the data in a column is edited and the data entered matches a specific string. This is what I have so far.
$("#jqxgrid").bind('cellendedit', function (event) { var args = event.args; var cellValue = args.value; var columnDataField = args.datafield; if ((columnDataField == 'rule') && (cellValue == 'Custom')) { console.log("*1"); // debug statement $("#jqxgrid").jqxGrid('setcolumnproperty', 'A', 'editable', true); $("#jqxgrid").jqxGrid('setcolumnproperty', 'B', 'editable', true); // line 8 $("#jqxgrid").jqxGrid('setcolumnproperty', 'C', 'editable', true); $("#jqxgrid").jqxGrid('setcolumnproperty', 'D', 'editable', true); } });
So when the user clicks on a cell in the “rule” column and enters the string “custom”, only the columns “A”, “B”, “C”, and “D” become editable. I tried this with two rows of data and I don’t understand why “*1” gets printed four times in the console log? I also get “Uncaught TypeError: Cannot set property ‘editor’ of null” in line 8 above but I double-checked my grid table has a column named B.
Also, how can I detect on startup if any of the rows have a value of “custom” in the “rule” column and if so, make the cells in columns “A”, “B”, “C”, and “D” editable for that row?
Hi qtipaddict,
The “getcellvalue” can be used for getting the value of a particular cell. I also suggest you to use “cellvaluechanged” event for updating whether a column is editable or not.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks Peter. The “cellvaluechanged” event works a lot better for me. But is there a way to set the editable property for a specific cell? I just realized that my code is enabling editable for the entire column and that is not what I intended.
I found this, http://www.jqwidgets.com/disable-editing-of-a-grid-row-or-cell/ but I need to enable/disable editing based on the value in another cell.
Okay, I think I figured it out.
var cellEdit = function (row) { var rows = $('#jqxgrid').jqxGrid('getboundrows'); if ( (rows[row]['rule'] == 'Custom') || (rows[row]['rule'] == 'custom') ) { return true; } else { return false; } }; $("#jqxgrid").jqxGrid( { width: '100%', editable : true, columns: [ { text: 'Rule', datafield: 'rule', editable : true, width: 100, columntype: 'textbox'}, { text: 'A', datafield: 'a', width: 100, columntype: 'numberinput', cellbeginedit: cellEdit }, { text: 'B', datafield: 'b', width: 100, columntype: 'numberinput', cellbeginedit: cellEdit }, { text: 'C', datafield: 'c', width: 100, columntype: 'numberinput', cellbeginedit: cellEdit }, { text: 'D', datafield: 'd', width: 100, columntype: 'numberinput', cellbeginedit: cellEdit } ] });
-
AuthorPosts
You must be logged in to reply to this topic.