Dynamic drop-down list in editor form
Dynamic drop-down list in editor form
peterbrowne
Posts: 314Questions: 54Answers: 0
I would like to replace the hard coded options in the code below with a dynamic data from MySQL DB through PHP. Is there clear way of doing this. An example would be good.
var editor = new $.fn.dataTable.Editor( {
ajax: "program_data/discipline_outcome_data.php",
table: "#discipline_outcome_table",
template: '#discipline_outcome_form',
fields: [ {
label: "Discipline:",
name: "discipline_outcome.discipline_fk",
type: "select",
placeholder: 'Choose discipline...',
placeholderDisabled: false,
placeholderValue: 0,
options: [
{ label: 'Emergency Medicine', value: 1 },
{ label: 'General Practice', value: 2 },
{ label: 'Internal Medicine', value: 3 },
{ label: 'Obstretics & Gynaecology', value: 4 },
{ label: 'Paediatrics', value: 5 },
{ label: 'Psychiatry', value: 6 },
{ label: 'Surgery', value: 7 }
]
},...
This discussion has been closed.
Answers
I have tried:
with get_disciplines.php:
That possibly should be:
but not working still...
The PHP script
get_disciplines.php
is returning:Is this for a regular left join? This example shows how to do it, with the docs here.
Allan
Hi Allan
The select list
discipline_outcome.discipline_fk
is actually just a list of disciplines that have no relationship with the the other data that is being served to the form fields. The name of the select list is probably misleading so I have changed it to:So what I am tying to do is just populate that select list with a separate function, bu it's not working. The JSON may be wrong from the PHP script or the method may be wrong to populate the list, I'm not sure:
The JSON from
get_displines.php
is like:and
get_disciplines.php
:I got it working using:
and in the editor:
and the
get_disciplines.php
:Excellent, thanks for reporting back,
Colin