Add "options" from DB Table and more custom options

Add "options" from DB Table and more custom options

karasukarasu Posts: 27Questions: 2Answers: 0

Hi,

to add a select box with options from DB table is easy with following code:

JS

var editor = new $.fn.dataTable.Editor( {
    ajax: 'php/table.example.php',
    table: '#example',
    formOptions: {
        main: {
            focus: 1,
        }
    },
    fields: [
        {
            "label": "Label:",
            "name": "example",
            "type": "select",
            "options": {
                "example": [{
                    "label": "4201",
                    "value": "4201"
                }]
            }
        }
    ]
} );

PHP

Editor::inst( $db, 'example', 'id' )
    ->fields(
        Field::inst( 'example' )
            ->options( 'example', 'name', 'example' )
    )

But how can I add more options ("names")

JS

"options": [
    "xy1",
    "xy2",
    "xy3"
]

PHP

Editor::inst( $db, 'example', 'id' )
    ->fields(
        Field::inst( 'beschreibung' )
            ->validator( 'Validate::notEmpty' )
    )

Is this possible or must I use only the last solution?

Thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 50,248Questions: 1Answers: 7,464 Site admin
    ->options( 'example', 'name', 'example' )
    

    This will show all options available in the example table. To add more names, you'd add more entries to that table.

    Allan

  • karasukarasu Posts: 27Questions: 2Answers: 0

    Thank you Allan, this is clear, if I add to more entries the table "example" that also these are displayed.
    But, the other users will also see this.
    Therefore, I wanted to show the entries from the table example and manually add entries in the code.

    Anyway, thanks for the answer.

    It is not optimal but I have now added all the entries from the table example manually in the code.

    Thank you

  • allanallan Posts: 50,248Questions: 1Answers: 7,464 Site admin
    Answer ✓

    To do that, what you would need to do is use the ->options() method with a function. That way you can read the information needed from the database, and then modify the array of entries, adding in whatever extra values are needed.

    Allan

Sign In or Register to comment.