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

CascadeDropdown popupEdit Grid Bind

2 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chatra
Top achievements
Rank 1
Chatra asked on 27 Jun 2014, 08:06 PM
Hi,

I have "Role" Grid with popup Editor with columns from Cascade drop downs on a popup.

The way I have set throwing error while creating new user Model.

The sample project attached below.

Can any one Help me in it.

//Parent Dropdown
  $("#Type").kendoDropDownList({
        dataTextField: "TypeDescription",
        dataValueField: "TypeID",
        autoBind: false,
        optionLabel: "Select Type...",
        dataSource: [
        { TypeDescription: "RoleType1", TypeID: 201 },
        { TypeDescription: "RoleType2", TypeID: 202 },
        { TypeDescription: "RoleType3", TypeID: 203 }
        ],
        index: 1
    });
 
//Child Dropdown
 
 $("#Role").kendoDropDownList({
        cascadeFrom: "Type",
       // cascadeFromField: "parentId",
        dataTextField: "RoleDescription",
        dataValueField: "RoleID",
        autoBind: false,
        optionLabel: "Select Role...",
        dataSource: {
            data: [
                    { RoleDescription: "Role1", RoleID: 101, TypeID: 201 },
                    { RoleDescription: "Role2", RoleID: 102, TypeID: 202 },
                    { RoleDescription: "Role3", RoleID: 103, TypeID: 202 },
                    { RoleDescription: "Role4", RoleID: 104, TypeID: 202 },
                    { RoleDescription: "Role5", RoleID: 105, TypeID: 203 }
                 ],
            filter: {
                "field": "RoleDescription",
                "operator": function (item) {
 
                    var data = $("#roleGrid").data("kendoGrid").dataSource.data();
 
                    var status = true;
 
                    if (e.model.isNew()) {
                        for (var j = 0; j < data.length; j++) {
                            if (item == data[j].Role.RoleDescription) {
                                status = false;
                                break;
                            }
                        }
                    }
 
                    return status;
                }
            }
       },
        index: 1
    });
 
 
//role Grid  data source
 
            roledataSource = new kendo.data.DataSource({
                data: e.model.Roles,
                pageSize: 10,
                serverPaging: false,
                serverFiltering: false,
                serverSorting: false,
                schema: {
                    model: {
                        id: "RoleID",
                        Role: "Role",
                        Type: "Type",
                        fields: {
                            RoleID: { type: "int" },
                            Role: { defaultValue: { Value: "", Text: "" } },
                            Type: { defaultValue: { Value: "", Text: "" } },
                        }
                    }
                }
 
            });
 
//Role model
 
 public class RoleType
    {
        public string TypeDescription { get; set; }
        public int TypeID { get; set; }
    }
 
    public class Role
    {
        public string RoleDescription { get; set; }
        public int RoleID { get; set; }
    }
 
    public class RoleModel
    {
        public int RoleID { get; set; }
        public Role Role { get; set; }
        public RoleType Type { get; set; }
    }

Thanks,
Chatrapathi chennam

2 Answers, 1 is accepted

Sort by
0
Chatra
Top achievements
Rank 1
answered on 27 Jun 2014, 08:08 PM
Please see sample project attached.

Have issue while creating New User because of RoleModel Cascade  setup.
0
Accepted
Daniel
Telerik team
answered on 01 Jul 2014, 02:38 PM
Hello,

The error will be thrown because a string is passed for the roledataSource data when adding new items. The usrdataSource does not specify a default value for the Roles field and so the value defined in the prototype of the model:
model: {
    id: "UserID",
    LastName: "LastName",
    FirstName: "FirstName",
    Email: "Email",
    OfficeNumber: "OfficeNumber",
    MobileNumber: "MobileNumber",
    FaxNumber: "FaxNumber",
    IsActive: "IsActive",
    Roles: "Roles",

will be passed. You should set a default value for the Roles in the fields definition:
fields: {
    UserID: { type: "int", validation: { required: true} },
    Roles: {defaultValue: []},
    ...
or remove the Roles field from the prototype:
model: {
    id: "UserID",
    fields: {
        UserID: { type: "int", validation: { required: true} },
or check the Roles value before setting it as data for the roledataSource.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Chatra
Top achievements
Rank 1
Answers by
Chatra
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or