Editor - row callback disable editor in specific cell
Editor - row callback disable editor in specific cell
dpanscik
Posts: 125Questions: 32Answers: 0
Hello.
I was wondering if there was a crafty way to disable editor for a specific cell using row callback?
I want to disable the editor for specific cells during certain "if then" logic conditions.
David
Answers
The Editor
dependent()
API can be used to conditionally disable fields.Kevin
Im not sure how to format this. The following disables the field in all rows. I am trying to disable the field only in certain rows.
As I suggested before use
dependent()
to conditionally disabled fields. Here is a simple example that disables theposition
filed if the value isDirector
.https://live.datatables.net/guwafemu/375/edit
The
disable()
API affects the form not the field and only takes one parameter - the field name. So you need to enable or disable when the form is open. YourrowCallback
is globally disabling the editor form fieldPoNumber
, not just for that row. You don't have anything to re-enable.Kevin
That solution works. I was hoping to do this within rowCallback just to keep all my logic in one spot.
On a side note: Once a decision is made to disable a field, I don't ever want to re-enable that particular field. So missing the "enable" function does not bother me.
Here is the next phase of the logic. And perhaps a even bigger reason to do this in rowCallback.
The logic using PoType does not work (obviously). If I cant do this in rowCallback, I need help to figure out how to do this here...
The problem is Editor doesn't keep track of disabled fields on a row by row basis. The
dependent()
API is used to customize the Editor form when opened. One of the options is to enable/disable fields. If youdisable()
a field its disable each time the form is opened until you useenable()
.Kevin
Here is a solution I pulled together combining the info from this forum thread and another forum thread.
Take a look at the
Submit data
section of thedependent()
docs. It explainsdata
is more than just the row data. It has different objectsrows
andvalues
that you can compare to. Maybe you will want to loop through either therows
object or thevalues
object to determine if the filed should be disabled. Something like this:https://live.datatables.net/guwafemu/376/edit
The Position field is disabled for the row with Ashton Cox.
Kevin