How to disable the Dropdown options in DataTable Editor?

How to disable the Dropdown options in DataTable Editor?

AJ31AJ31 Posts: 4Questions: 3Answers: 0
var editor;
 
$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "../php/data.php",
        table: "#example",
        fields: [ {
                label: "User:",
                name:  "user"
            }, {
                label: "User Data:",
                name:  "selections",
                type:  "select",
                options: [
                    { label: "abc", value: "abc" },
                    { label: "xyz", value: "xyz" },
                    { label: "pqr", value: "pqr" },
                    { label: "def", value: "def" },
                    { label: "lmn", value: "lmn" }
                ]
            }
        ]
    });
});

I have the DataTable editor defined as shown in the above code snippet. Under the fields, I want to disable the 'xyz' and 'def'
select options for the User Data label.I tried adding {label: "xyz", value: "xyz", "disabled": true} but that didn't work for me.
Is there any other option to do that?How do I achieve this?

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    You'll need to use the field().input() method to get a reference to the select and then manipulate its options as required - e.g.:

    editor.field('selections').input().find('option[value=xyz]').prop('disabled', true);
    

    This is required as there isn't currently an option to specify the disabled state through the options parameter for the field.

    Allan

Sign In or Register to comment.