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

Dropdowns and Custom Editors

1 Answer 14 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 19 Dec 2018, 04:42 PM

I am using a grid to display system user information and have followed the guide for "Edit Records Using External Forms"

I need to implement a drop down editor for a few of the data fields associated with the user (country, userGroup, Roles) and have been struggling to accomplish that goal. 

When I select a user I am using MVVM to populate the fields with the existing information.

This works great for text fields. But fields that require a drop down, will populate with the data source options but will not start with the correct selection already associated with the user.

I hope this is enough information to convey my issue. Let me know if I can provide anything else. 

 

 

 

<input data-role="dropdownlist"
       data-text-field="name"
       data-value-field="groupID"
       data-bind="value: selected.groupID,
                  source: loginGroupsDS"
/>
 
...
 
var userViewModel = kendo.observable({
...
        loginGroupsDS: new kendo.data.DataSource({
            transport: {
                read: {
                    type: 'POST',
                    dataType: 'json',
                    url: crudServiceBaseUrl+'getLoginGroups'
                }
            },
            schema: {
                data: "groups"
            }
        }),
        selected: {},
...
}
 
// where selected contains the data from the select grid row
 
// loginGroupsDS returns data in the form
groups: {[
    {groupID: 2, name: "Administrator"}

 

    ]}

 
// userViewModel.selected has the same form
selected.groupID: {groupID: 2, name: "Administrator"}

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 21 Dec 2018, 10:57 AM
Hi Sam,

In your specific scenario, I think you need a data-value-primitive="true" setting in the DropDownList because you need to bind only the ID value of the DropDownList data items to the field in the Grid.
<input data-role="dropdownlist"
       data-text-field="name"
       data-value-field="groupID"
       data-value-primitive="true"
       data-bind="value: selected.groupID,
                  source: loginGroupsDS"
/>


You can read more about this here:
View-Model Fields with Value Field of Primitive Value



Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Sam
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or