How to supply custom types in schema object.

2 posts, 0 answers
  1. Sajid Ali
    Sajid Ali avatar
    12 posts
    Member since:
    Aug 2010

    Posted 20 May 2014 Link to this post

    I am trying provide a custom type in the schema of the datasoure object of kendogrid. Here is my code sample.


    oThis.productsDataSource = new kendo.data.DataSource
                ({
                    pageSize: 10,
                    transport: {
                        read: {
                            url: crudServiceBaseUrl + "GetAll",
                            dataType: "json"
                        },
                        update: {
                            url: crudServiceBaseUrl + "Post",
                            contentType: "application/json",
                            type: "POST",
                            dataType: "json"
                        },
                        destroy: {
                            url: crudServiceBaseUrl + "Delete",
                            contentType: "application/json",
                            type: "DELETE",
                            dataType: "json"
                        },
                        create: {
                            url: crudServiceBaseUrl + "New",
                            contentType: "application/json",
                            type: "POST",
                            dataType: "json"
                        },
                        parameterMap: function (data, type) {
                            if (type !== "read" && data.models) {
                                return kendo.stringify(data.models[0]);
                            }
                        }
                    },
     
                    schema: {
                        model: {
                            id: "Id",
                            fields: {
                                Id: { editable: false, nullable: true },
                                Name: { validation: { required: true } },
                                ResourceCostBandId: {
                                    //type: "servicePath.SLF.solutionEngine.Model.EntityRef",
                                    fields: {
                                        Id: { editable: false },
                                        Name: { editable: false }
                                    },
                                    validation: { required: true }
                                }
                            }
                        }
                    },
                    batch: true
                });
    //type: "servicePath.SLF.solutionEngine.Model.EntityRef",
    How I can specify this type while defining a schema. My "EntityRef" has two fields
    id and Name which are of type strings.

    var grid = this.element.kendoGrid({
                columns: [
                    { field: "Name", title: "Name", width: 200, validation: { required: true } },
                    {
                        // Following binding not working but when I change it to following
                        //field: "ResourceCostBandId"
                        // It works but then it set the value on the ResourceCostBandId. I want it to be set on ResourceCostBandId.Id
                        field: "ResourceCostBandId.Id", title: "Cost Band",
                        width: 200, validation: { required: true },
                        template: "#= ResourceCostBandId.Name #",
                        editor: function (container, options) {
                            $('<input required data-text-field="Name" data-value-field="Id" data-bind="value:' + options.field + '"/>')
                                .appendTo(container)
                                .kendoDropDownList({
                                    dataTextField: "Name",
                                    dataValueField: "Id",
                                    dataSource: oThis.controller.$scope.ResourceCostBands,
                                    index: 0
                                });
                        }
                    },
                    { command: ["edit", "destroy"], title: " ", width: "172px" }
                ],
                toolbar: ["create"],
                pageable: { "pageSize": 5, "refresh": true, "pageSizes": true },
                autoBind: true,
                dataSource: oThis.productsDataSource,
                resizable: true,
                editable: 'inline',
                selectable: true,
     
            });

    Anybody have idea who I can do that.

    Thanks
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 22 May 2014 Link to this post

    Hello Sajid,

    The field's type should be any of the basic JavaScript types, such as string, number, date, boolean or object. Defining custom types or specifying the type of nested objects is currently not supported, so all nested properties will be treated as strings. This could be avoided by flattening the model, then specifying the type as usual.

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top