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

Kendo Grid DropDownList NewRecord Saving Issue In Popup Editing

2 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saima
Top achievements
Rank 1
Saima asked on 07 May 2014, 05:15 AM
Hi
I have an issue in Saving. I have dropDownList Language In Editor.  When I Edit existing record values are correctly send to My web Service And record saved ok.
But when i Click On Add New Record Button and Save it, DropDownList Data sends both Value and ext Field Like Language[text]=English, Language[value]=English
I have seen it in Firebug

Here is my code
$("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "/fsMail/services/dataService.asmx/GetEmlContacts",
                            dataType: "Json"
                        },
                        update: {
                            url: "/fsMail/services/dataService.asmx/SaveContacts",
                            dataType: "json"
                        },
                        create: {
                            url: "/fsMail/services/dataService.asmx/SaveContacts",
                            dataType: "json"
                        },
                        destroy: {
                            url: "/fsMail/services/dataService.asmx/DeleteContact",
                            dataType: "json"
                        },
                    }, //end of transport
                    schema: {
                        model: {
                            id: "contactId",
                            fields: {
                                contactId: { editable: false },
                                businessName: { validation: { required: true} },
                                firstName: { validation: { required: true} },
                                lastName: { validation: { required: true} },
                                language: { nullable: true },
                                country: { nullable: true },
                                address: { nullable: true },
                                city: { nullable: true },
                                gsm: { nullable: true },
                                email: { nullable: true },
                                isActive:{type: "boolean",defaultValue: true}
                            }
                            }//end of model
                        },
                        pageSize: 10
                    },//end of schema
                    
                    columns: [
                        { field: "contactId",title: "ContactId", hidden: true },
                        { field: "businessName", title: "Business Name", width: 200 },
                        { field: "firstName", title: "Contact Title", width: 200 },
                        { field: "lastName", title: "Last Name", hidden: true },
                        { field: "language", title: "Language", width: 100, editor: langDropDownEditor},
                        { field: "country", title: "Country", width: "100px", editor: countryDropDownEditor },
                        { field: "address", title: "Address", hidden: true },
                        { field: "city", title: "City", width: 100 },
                        { field: "gsm", title:"GSM",hidden: true },
                        { field: "email",title:"Email", hidden: true },
                        { field: "isActive",title:"Active", hidden: true },
                        { command: ["edit", "destroy"], title: " ", width: "160px" },
                    ],
                     
                    toolbar: ["create"],
                    editable:  "popup",
                    filterable: true,
                    groupable: false,
                    sortable: true,
                    selectable: true,
                    pageable: {
                        refresh: true,
                        pageSizes: false,
                        buttonCount: 3
                    },
                    
                });
                 
                function langDropDownEditor(container, options) {
                    $('<input data-text-field="text" data-value-field="value" data-bind="value:' + options.field + '"/>')
                    .appendTo(container)
                    .kendoDropDownList({
                        autoBind: false,
                        dataSource: [
                            { text: "English", value: "English" },
                            { text: "German", value: "German" },
                            { text: "French", value: "French" }
                        ]
                         
                    });
                }
            });

Please help me how should i send value in Adding new record

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 08 May 2014, 04:32 PM
Hello Saima,

What you described is probably because of the MVVM framework and it's primitive and complex binding behavior. Could you try to set the data-value-primitive="true" to that DropDownList editor that you are using?

http://docs.telerik.com/kendo-ui/getting-started/framework/mvvm/bindings/value#use-the-value-binding-with-a-select-widget-to-update-the-view-model-field-with-the-value-field-when-the-initial-value-is-null.

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Saima
Top achievements
Rank 1
answered on 13 May 2014, 05:46 AM
I have solved my problem by finding a clue from Stack overflow and redefine my datasource that binds grid to return language text and language value.
Here is my class
//--------------------------------------------------------
   //Class ContactDef
   //--------------------------------------------------------
   public class ContactDef
   {
       public string contactId;
       public string contactKey;
       public string creationDate;
       public string businessName;
       public string firstName;
       public string lastName;
       public string address;
       public string city;
       public string gsm;
       public string email;
       public string isActive;
       public LanguageModel language { get; set; }
       public CountryModel country { get; set; }
 
       public ContactDef() { }
       public class LanguageModel
       {
           public string text { get; set; }
           public string value { get; set; }
       }
 
       public class CountryModel
       {
           public string text { get; set; }
           public string value { get; set; }
       }
 
       public ContactDef(string contactId,string businessName
           ,string firstName,string lastName
           ,CountryModel country,string address,string city
           ,string gsm,string email
           , string isActive
           , LanguageModel lang)
       {
            
           this.contactId = contactId;
           this.businessName = businessName;
           this.firstName = firstName;
           this.lastName = lastName;
           this.country = country;
           this.address = address;
           this.city = city;
           this.gsm = gsm;
           this.email = email;
           this.isActive = isActive;
           this.language = lang;
       }
   }
Tags
Grid
Asked by
Saima
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Saima
Top achievements
Rank 1
Share this question
or