This is a migrated thread and some comments may be shown as answers.

Define schema for individual fields.

2 Answers 195 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Travis
Top achievements
Rank 1
Travis asked on 24 Jan 2013, 05:20 AM
I am working with a kendo grid with some drop downs but I am running into issues with how the data is send back to the server.
I do not want to provide default settings for the combo boxes but if I don't I only get the id rather than the full object sent back to the server.  With my datasource below I correctly get no default set however I am only given by the id - not the full object.  Can I define the data structure of Site and Role within the schema without setting a default value?
new kendo.data.DataSource({
                transport: {
                    read: {                      
                        url: "json/users/getXForUser/" + userID,
                        dataType: "json"
                    },
                    create: {
                        url: "json/users/createUpdateX/" + userID,
                        type: "POST"
                        
                    },                  
                schema: {
                    model: {
                        id: "ID",
                        fields: {
                            Site: { }, // this is a combobox result and I want the object back with ID and Name
                            Role: { } // this is a combobox result and I want the object back with ID and Name
                        }
                    }
                }
            });

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 25 Jan 2013, 02:40 PM
Hi Travis,

Can I define the data structure of Site and Role within the schema without setting a default value?
Yes you can, setting the default value is not always mandatory. If you want to modify the request parameters send back to the server please consider using the parameterMap function of the transport. 

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Travis
Top achievements
Rank 1
answered on 02 Feb 2013, 02:12 PM
Thanks! That did 50% of the job.  The other trick that was required was to make a tiny change to my editor.  What was happening for me is the editor would load and select the first item from the list but not trigger the selection even hence the values pushed to the server were blank.  By triggering the change on dataBound that problem goes away.  Maybe I am doing something wrong in my setup by for now - problem resolved!
function roleDropDownEditor(container, options) {
                $('<input data-selector-type="role" data-text-field="Name" data-value-field="ID" data-bind="value:' + options.field + '"/>')
                    .appendTo(container)
                    .kendoDropDownList({
                        dataTextField: "Name",
                        dataValueField: "ID",                      
                        placeholder: "Please Select",
                        dataSource: {
                            transport: {
                                read: {
                                    url: "json/data/getSiteRoles",
                                    type: "GET"
                                }
                            },
                            schema: {
                                model: {
                                    id: "ID",
                                    fields: {
                                        Name: {  }                                       
                                    }
                                }
                            }
                        },    
                       // once data bound trigger the change event so that the default selection actually does get set .                 
                        dataBound: function (e) {
                            e.sender.trigger("change");
                        }
                    }).data("kendoDropDownList");
            }
Tags
Data Source
Asked by
Travis
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Travis
Top achievements
Rank 1
Share this question
or