How to disable Single Field only based the value of the Field
How to disable Single Field only based the value of the Field

in Editor
I am using Datatable Editor with inline configuration and i have different fields. Now I want disable a specific field only based on the value. Field type is Select and i am using select2 plugin for it.
E.g. There a 3 Options in the Select and i want to disable editor for this field if value is "Unknown"
how can i do this. ? i have tried serveral options like PreOpen callback at that i am unable to get which field is currenly going to edit in inline mode of editor
Answers
I think it shouldn't make a difference what editing mode you are using. Here is something I use frequently:
Hi, @rf1234
I am using select2 plugin for inline edit. this way it doesn't work. Field is still editable. it doesn't stop from editing.
Can you post a link to a case case showing to issue so we can properly understand the problem and offer some help?
Allan
here is my Field config
{
"type": "select2",
name: "fieldType",
"opts": {
"allowClear": false,
minimumResultsForSearch: -1,
dropdownParent: $('.content'),
},
options: [
{label: 'Field1', value: 'Field1'},
{label: 'Field2', value: 'Field2'}
]
}
fieldType value can 'Known' so in that case i don't want to edit that field. i am using inline edit style
Are you using full row editing, or just individual cells? If individual cells, is the issue not that the field becomes disabled (or not), but rather than you don't want it to enter into the editing state at all? If so, how are you triggering inline editing - are you calling
inline()
? If that is the case, then you'd need a logic condition before that to check if the field should become editable or not.A link to a test case really would help.
Allan
Hi, @allan
I am using
Inline()
Api for individual cell editing with Select2 Plugin configuration is{
"type": "select2",
name: "fieldType",
"opts": {
"allowClear": false,
minimumResultsForSearch: -1,
dropdownParent: $('.content'),
},
options: [
{label: 'Field1', value: 'Field1'},
{label: 'Field2', value: 'Field2'}
]
}
Now for this field there is third value 'Unknown' while table initialized for that case I just want to disable editing for this Field only incase if value is "Unknown" else it should editable with 2 options give. There are more fields with Inline configuration those should be editable.
Can you show me how you are calling the
inline()
method please?As I say, a link to a test case would help (a lot).
Allan
Hi, @allan
Can you please just guide me how to Stop opening Inline Editor for the Single field only by checking its name and Value!. Where i can check that Inline Editor should enable or not ?
there is option in PreOpen(). but there i can't find which field it is going to edit !
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
I have been trying to understand what you mean, unsuccessfully so. Please provide a test case. If you can't get the test case working please post it anyway. We might be able to understand your problem a little better - and hopefully help you!
displayed()
is the method to get displayed fields, but because you are wanting to check inpreOpen
, the field hasn't been displayed and thus the method will return an empty array.You will need to use a different approach, which I alluded to above when I asked for the code for how you are triggering editing. You haven't provided that, so I'm going to make a few assumptions - hopefully it will still apply to your use case.
What you probably need to do is store which field it is that editing was being triggered on:
That assumes that
columns.data
matches thefield.name
(if not, then the logic would need to be changed).Then you can use
preOpen
to check the value of the disabling field and also whatcurrentField
is andreturn false;
if needed.It would be easier to simply wrap
inline()
in anif
condition, but I don't think that would be sufficient, since the inline editing action is async if there is already a field being edited.Allan