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

How to supply custom types in schema object.

1 Answer 473 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sajid Ali
Top achievements
Rank 2
Sajid Ali asked on 20 May 2014, 09:51 AM
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

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 22 May 2014, 08:13 AM
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!
 
Tags
Grid
Asked by
Sajid Ali
Top achievements
Rank 2
Answers by
Alexander Popov
Telerik team
Share this question
or