а

Dhtmlxform Select load data from database


#1

Dear All.
I am trying new Dhtmlx Suite 6, there is a “select” item in my form. how to load the options data of select item from database ? in Dhx 5 there is an attribute connector to get the options from database.

Thank you


#2

Such feature is not available for the select item.
Please, try to use the combo item.
using the getItem method you are able to get the dhtmlxCombo object of combo item an load the required data to it.
https://docs.dhtmlx.com/suite/form__combo.html#workingwithcombo


#3

thanks for your help, semantik :grinning:


#4

Just throwing in an update for anyone coming back to this topic: You can use the same concept as semantik’s idea above with the combo item, but using the select item. Maybe this has been added since semantik answered previously.

var url = "/path/to/REST/api"
dhx.ajax.get(url).then(function(data){
    var opts = [{value:"",content:""}]; // I usually include a blank "not set" option
    for (var i=0;i<data.records.length;i++){
        var rec = data.records[i];
        opts.push({value:rec.id,content:rec.text});
    }
    var sel = form.getItem("select_id");
    sel.setConfig({label:"Label Text",options: opts});
});