1
votes

How would I bring in a select drop down into one of my Kendo ui grid columns using remote data?

The documentation is very limited on this subject, specifically with my requirement which is:

To have a list of options from my PHP/MySQL script populate the drop down menu.

If one of those options is already set based on a query in the database, have that option in the menu already selected.


Based on the answer provided I now have the following, but it is not working. I get a dropdown list with a load of options all 'undefined':

function categoryDropDownEditor(container, options) {
$('<input required data-text-field="'+options.field+'" data-value-field="'+options.field+'" data-bind="value:' + options.field + '"/>')
    .appendTo(container)
    .kendoDropDownList({
        autoBind: false,
        dataTextField: "text",
        dataValueField: "value",
        dataSource: {
            type: "POST",
            transport: {
                read: ROOT+"user/branch-list"
            }
        },
        index: 0
    });
}

My PHP script just returns JSON like so:

[{text: "Germany", value: "1"}]
2
Please, remove data-text-field and data-value-field from the input definition.OnaBai

2 Answers

1
votes

You can use editor when define the column for that field.

{ field: "color", title: "Color", editor: editColor }

where editColor is a function defined as:

var data = [
     { text: "Black", value: "1" },
     { text: "Orange", value: "2" },
     { text: "Grey", value: "3" }
];

function editColor(container, options) {
    $('<input data-bind="value:' + options.field + '" '"/>')
            .appendTo(container)
            .kendoDropDownList({
                dataTextField: "text",
                dataValueField: "value",
                dataSource: data,
                index: 0,
            });
}

You might set in kendoDropDownList whichever configuration option you need.

0
votes

Also you may want to check that your datasource is parsing your data correctly.

For example my json looks like this you can see that the actual records are are contained within the _ENTITIES array. So in order for the the datasource to parse this correctly I have to specify data : "_ENTITIES" in the schema for my datasource. I hope this helps

schema : { model : myModel, data : "__ENTITIES" }

{"_entityModel":"Contact","_COUNT":13,"_SENT":13,"_FIRST":0,"_ENTITIES":[{"_KEY":"177","_STAMP":16,"ID":177,"firstName":"","middleName":"","lastName":"","ContactType":{"_KEY":"2","_STAMP":4,"ID":2,"name":"Home","contactCollection":{"_deferred":{"uri":"/rest/ContactType(2)/contactCollection?$expand=contactCollection"}}},"addressCollection":{"__deferred":{"uri":"/rest/Contact(177)/addressCollection?$expand=addressCollection"}}},

{"_KEY":"180","_STAMP":5,"ID":180,"firstName":"a","middleName":"b","lastName":"c","ContactType":{"_KEY":"2","_STAMP":4,"ID":2,"name":"Home","contactCollection":{"_deferred":{"uri":"/rest/ContactType(2)/contactCollection?$expand=contactCollection"}}},"addressCollection":{"_deferred":{"uri":"/rest/Contact(180)/addressCollection?$expand=addressCollection"}}}