Define schema for individual fields.

3 posts, 1 answers
  1. Travis
    Travis avatar
    8 posts
    Member since:
    Nov 2012

    Posted 23 Jan 2013 Link to this post

    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. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2894 posts

    Posted 25 Jan 2013 Link to this post

    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!
  3. Travis
    Travis avatar
    8 posts
    Member since:
    Nov 2012

    Posted 02 Feb 2013 Link to this post

    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");
                }
Back to Top