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

DataSource has data but count() returns 0 and get() returns undefined

2 Answers 554 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jesper
Top achievements
Rank 1
Jesper asked on 19 Jun 2012, 07:13 AM
I fetch data from the server using like so (the fetch url has been predefined using jQuery.ajaxSetup()):

var dataSourceStatistics = new kendo.data.DataSource({
    transport: {
        read: {
            data: {
                f:'getCustomerStats',
                fromDate:function () {
                    return kendo.toString(kendo.parseDate(calendarstart.value()), "yyyy-MM-dd")
                },
                toDate:function () {
                    return kendo.toString(kendo.parseDate(calendarend.value()), "yyyy-MM-dd")
                },
                custStats:null
            }
        }
    },
    schema: {
        data: function(data) {
            return data.result.custStats.Record;
        },
        model:{
            id: "Employee",
            fields: {
                Employee: "Employee",
                Value: "Value",
                ValueUsed: "ValueUsed",
                ValueLeft: "ValueLeft"
            }
        }
    },
    pageSize: 10
 
});

After I execute read() the DataSource contains data, and the objects look OK. 
Example:

[{"Employee":"John Doe","ValueUsed":"50","ValueLeft":"0"}]


But executing the method total() returns 0 and get(index) always returns undefined. 
What am I doing wrong?

2 Answers, 1 is accepted

Sort by
0
Jesper
Top achievements
Rank 1
answered on 19 Jun 2012, 09:38 AM
I now defined total() manually at initialization, and it works. But I seriously can't see why that should be necessary. Shouldn't total() just count the number of models that were successfully parsed when data was read from the remote?
get(index) still returns undefined. I'm beginning to feel that Kendo UI documentation isn't what it should be.
0
Jesper
Top achievements
Rank 1
answered on 19 Jun 2012, 10:20 AM
I misread the documentation for get(). It expects an Id, not an int. D'Oh :)
Tags
Data Source
Asked by
Jesper
Top achievements
Rank 1
Answers by
Jesper
Top achievements
Rank 1
Share this question
or