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

Remote data does not respect defaultValue

3 Answers 184 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jesper
Top achievements
Rank 1
Jesper asked on 20 Jun 2012, 06:04 AM
I'm getting data from a remote like so:

var dataSourceStatistics = new kendo.data.DataSource({
    transport: {
        read: {
            data: {
                f:'getCustomerStats',
                fromDate:function () {
                    return "2012-01-01";
                },
                toDate:function () {
                    return "2012-06-19";
                },
                custStats:null
            }
        },
        update: {
 
        }
    },
    schema: {
        data: function(data) {
            return data.result.custStats.Record;
        },
        total: function(data) {
            return data.result.custStats.Record.length;
        },
        model:{
            id: "EmployeeId",
            fields: {
                Employee: {
                    editable: false
                },
                EmployeeId: {
                    editable: false
                },
                ValueCandE: {
                    type: "number",
                    defaultValue: 0
                },
                ValueE: {
                    type: "number",
                    defaultValue: 0
                },
                ValueEandCandM: {
                    type: "Number"
                },
                ValueEandM: {
                    type: "Number"
                }
            }
        }
    }
});

The remote data does not always contain the ValueE and ValueCandE fields.
Currently, all the missing fields show up as null in the models.

Why doesn't the DataSource respect my default values?

3 Answers, 1 is accepted

Sort by
0
Jesper
Top achievements
Rank 1
answered on 21 Jun 2012, 07:18 AM
Models that I explicitly create respect the default values. Is this intended behaviour, that remote data does not respect default values? If so: please change it or make the behaviour optional.
0
Jeff
Top achievements
Rank 1
answered on 16 Oct 2013, 11:49 PM
I would also like a response to this issue. I was pulling my hair out over an issue with using kendo.data.Model before eventually discovering a couple major issues with this class:
  1. The defaults defined in the schema are only respected when creating a new instance of a model using null or an empty object.
  2. The defaults and schema types are completely ignored for any properties/fields not included in the data object. In other words, given a model named, MyModel with schema which defines three properties prop1, prop2 and prop3 (all strings for this example), If I create a new instance without supplying all three properties (i.e. var test = new MyModel({ prop1:'A', prop3:'C'}); ), the test variable will not have three properties, it will only have prop1 and prop2.
http://www.nesterovsky-bros.com. They have a fantastic solution which involves extending the Model class to fix these issues (and adds a few other features). The full solution can be found at 
http://www.nesterovsky-bros.com/weblog/2013/04/03/KendoUIExtendedModel.aspx

Is there any chance the Kendo team could make these changes to the library?

Thanks.
0
Petur Subev
Telerik team
answered on 22 Oct 2013, 08:08 AM
Hello,

Indeed the dataSource schema model defaultValues are taken into account only when creating new record. In case you want to display defaultValues for fields that are not included in the read response then you need to use the dataSource.schema.parse function to add the missing fields manually with the corresponding default vlaues.

@Jeff

In case you have a suggestion which you think will be a good addition to the Kendo framework and many users will find it useful please post it as an idea to the UserVoice page where more people can vote for it and the Dev team can consider its implementation.

Thank you for the interest and the understanding.

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!
Tags
Data Source
Asked by
Jesper
Top achievements
Rank 1
Answers by
Jesper
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or