Add "options" from DB Table and more custom options
Add "options" from DB Table and more custom options
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
This discussion has been closed.
Answers
This will show all options available in the
example
table. To add more names, you'd add more entries to that table.Allan
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
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
I also need that please.
I want to add an extra value in options list returned by db.
Don't bother ,i found this https://datatables.net/forums/discussion/34404/editor-inline-select-field-options and it worked like a charm!