Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Item To kendoDropDownList

I am trying to add a item to the kendoDropDownList, it seems to add the option but not set the value and text. Inspecting the select it just adds a new option

 <option></option>

Here is what I am using

 $("#nameList").data("kendoDropDownList")
     .dataSource.add({ "text": "Joe", "value": "Joe" });

UPDATE

Here is my datasource model and the requestEnd as suggested but the values seem to get messed up

datasource_people = new kendo.data.DataSource({
        type: "json",
        serverFiltering: true,
        transport: {
            read: {
                dataType: 'json',
                type: 'GET',
                url: '/restful/people/'
            }
        },
        filter: {
            field: "status",
            operator: "eq",
            value: 1
        },
        schema: {
            data: function(response) {
                return response.data.plaintiffs;
            },
            model: {
                id: "person_id",
                fields: {
                    person_id: {type: "number"},
                    name: { type: "string"}
                }
            },
            errors: "error",
            total: function(response) {
                return response.data.total;
            }
        }
    });

Then Later

$("#people_list").kendoDropDownList({
                    dataTextField: "text",
                    dataValueField: "value",
                    dataSource: {
                        datasource_people,
                        requestEnd: function (e) {
                            e.response.push({text: "John", value: "John"});
                        }
                    }
                });
like image 920
Hector Avatar asked May 12 '15 20:05

Hector


1 Answers

After some searching it was quite simple but this worked for exactly what i needed.

$("#people_list").getKendoDropDownList().dataSource.insert({
    person_id: "John",
    name: "John"
})
like image 179
Hector Avatar answered Oct 01 '22 18:10

Hector