Updating Select Field from database query
Updating Select Field from database query
I am a bit lost on what to do.
$.ajax({
url: 'checkStockNr.php',
data:'checkType=getMMYear&MMval='+MMVal+' '
})
.done(function(Ydata) {
var YdataArray = $.parseJSON(Ydata);
var x,text,setText;
for (x in YdataArray) {
text = YdataArray[x]['RegYear'];
editorNewForm.field('YEAR').update([{"label":text}]);
}
console.log(text);
// editorNewForm.field( 'YEAR' ).set('Ydata');
})
i only manage to get the last value out of the array to be added to the select list.
this is the php output from Ydata [{"RegYear":"1998"},{"RegYear":"1999"}]
but i seem to only get "1999" in the dropdown list.
Im New at datatables and im sure im making a obvious mistake.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
The issue is that you are calling
field().update()
once for every option. It expects the full list of options to be passed in, which explains why you are only ever seeing the final item in the array.What you need to do is create an array of objects with
label
andvalue
and then pass that resulting array intofield().update()
just once (i.e. the array has all the options in it).Allan
Am i at least close?
now its only creating one select option with both values, what am i missing?
Fixed Thank You. Found the solution here --- http://datatables.net/forums/discussion/9899
Great stuff - good to hear you've got it working now :-)
Allan