jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Disable Edit Based on Other Column Value
This topic contains 5 replies, has 2 voices, and was last updated by Peter Stoev 10 years, 9 months ago.
-
Author
-
We’ve got a grid on a page where editing is controlled by the user’s permission level. The grid has checkboxes (if it’s editable), or a cellsrenderer to display the value (if it’s uneditable). I now have a new requirement to make the checkbox columns uneditable based on the value of another column in the grid. The problem I’m having w/ this is that the editable/uneditable is being handled by our Coldfusion code, not anything within the grid javascript.
Here’s the column definition for one of the columns:
{text: "Requires Credits", datafield: 'RequiresCredits', width: '8%', columngroup:'Enrollment', <cfoutput><cfif info_edit>columntype: 'checkbox', cellbeginedit: beginVariantEdit<cfelse>cellsrenderer: requires_credits</cfif></cfoutput>, cellsalign: 'center', sortable: false, filterable: false},
You’ll notice the Coldfusion if statement controlling whether or not the column is rendered as a checkbox w/ a beginedit function, or if the cellsrenderer is used. I’ve tried adding code to the cellbeginedit function to test the other column value, but the grid still displays a checkbox, which is changable, so it’s going to be pretty confusing for the user. I need to be able to do this check in the grid javascript, since each row will potentially have a different editable state.
Hi shimmoril,
It is possible as a solution to implement a custom Checkbox editor like in this demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/customrowcelledit.htm?arctic. The checkbox is displayed only when the cell is in edit mode. Hope this help you.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Sorry, I’m not following how that will help in my situation. For each row I need to check the value of a column in that row. If it’s 1, then other columns on that row are editable. If it’s 0, they’re not. In the example provided you’re just checking the row number and then setting a type of edit control, not actually preventing editing.
There also doesn’t appear to be a way to capture the change of value of a column, which is why we’re using cellbeginedit – I need to know if the value has changed in order to save the data.
Hi shimmoril,
The example shows you how to create a custom Checkbox editor, because as far as I understood from your post, you cannot achieve what you try to achieve with the current editor. Yes, with cellbeginedit you can cancel cell editing. You can cancel it by setting a column’s editable property to false, too. This can be done dynamically through the “setcolumnproperty” method.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Thanks for the response Peter. Re this:
you cannot achieve what you try to achieve with the current editor
Actually my original question was meant to determine if it is possible w/ our current editor – obviously that’s the least “expensive” option for us.
Yes, with cellbeginedit you can cancel cell editing. You can cancel it by setting a column’s editable property to false, too. This can be done dynamically through the “setcolumnproperty” method.
I’m not sure how cancelling editing after they’ve clicked helps me at all – my primary concern is that it would still visually appear to be editable, which would be confusing to the users. I’ve got the same concerns w/ the setcolumnproperty option – aside from having to loop through each row and update the property for each column (in the ready function I guess?), I’d still be left with cells that look editable, even if they’re not.
Utimately, what I’m looking for the the ability to display editable and uneditable rows differently – like we’re currently doing w/ the cellbeginedit vs the cellsrenderer by on a row-by-row basis, instead of the whole grid.
Hi shimmoril,
If you think a little about the solution I suggested, you will find out that creating a custom checkbox editor as in the demo I pointed you is the best option for you. It works like a normal editor – checkbox is displayed only in edit mode and you can determine when to allow or disallow the editing through the cellbeginedit.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.