Define select options only once in editor

Define select options only once in editor

kicrkicr Posts: 3Questions: 1Answers: 0

Hello,

I have 8 select fields with the same 4 options. So I defindet the options 32 times. Is there a way to define the options only once and reuse them vor every select field? Actually my code looks like this:

var editor = new $.fn.dataTable.Editor( {
        ajax: 'php/doodle_table1.php',
        table: '#doodle_table1',
        fields: [
            {
                "label": "Name:",
                "name": "name"
            },
            {
                "label": dateMsg,
                "name": "termin1",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            },
            {
                "label": dateMsg2,
                "name": "termin2",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            },
            {
                "label": dateMsg3,
                "name": "termin3",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            },
            {
                "label": dateMsg4,
                "name": "termin4",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            },
            {
                "label": dateMsg5,
                "name": "termin5",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            },
            {
                "label": dateMsg6,
                "name": "termin6",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            },
            {
                "label": dateMsg7,
                "name": "termin7",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            },
            {
                "label": dateMsg8,
                "name": "termin8",
                "type": "select",
                "options": [
                    {"label": "", "value": ""},
                    {"label": "ja", "value": "1"},
                    {"label": "nein", "value": "0"},
                    {"label": "vielleicht", "value": "vielleicht"}
                ]
            }
        ]
    } );

Thanks for your help, I really appreciate it!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Sure - do this:

    var options = [
                        {"label": "", "value": ""},
                        {"label": "ja", "value": "1"},
                        {"label": "nein", "value": "0"},
                        {"label": "vielleicht", "value": "vielleicht"}
                    ];
    

    Then in the Editor configuration simply:

    "options": options
    

    for all of them :-)

    Allan

  • kicrkicr Posts: 3Questions: 1Answers: 0

    Thank you Allan!

This discussion has been closed.