I've been struggling with this all day, and I can't believe it's this hard to get the total number of records returned in a datasource! Very frustrating... I've read the documentation over and over and nothing seems to work for me. I've got a json response that is structured like this:
Here's my dataSource code:
So when I want to get the total I pass a function to this dataSource (i.e. callback) and return it in the requestEnd event, like so:
I put this after the schema block in the dataSource, although I don't think it should matter...? This event never fires, or if it does I cannot break inside of it in Chrome. So I tried using the change event in a similar manner, that never fires either. Here's a complete function attempting to get the dataSource and retrieve the total (normally I would not include the events in the dataSource and then bind them again after the dataSource, but for brevity sake...):
I just want to do a dataSource.total() and find out if there's anything in my dataSource, and I CANNOT. It always returns 0! And I can see that my response is not zero, so why does it always say zero for the total?? I believe I'm following standard async methods to make sure the response has completed, so I'm stumped and completely frustrated, once again.
I know I sound pretty whiny in this message, but it's just been a long day. I sure would appreciate any help!
Thanks,
Eddie
{ records: [], totalRecordCount: 20, queryRecordCount: 20 }
Here's my dataSource code:
return
new
kendo.data.DataSource({
transport: {
read: {
type:
"POST"
,
data: request,
cache:
false
,
url: ServiceUri +
"/Associates"
,
dataType:
"json"
}
},
serverPaging:
false
,
pageSize: 25,
schema: {
data:
"records"
,
total:
"totalRecordCount"
,
model: {
fields: {
Id: { type:
"number"
},
Name: { type:
"string"
},
Sex: { type:
"string"
},
Race: { type:
"string"
},
Height: { type:
"string"
},
Weight: { type:
"string"
},
Age: { type:
"number"
},
DOB: { type:
"date"
},
LastChanged: { type:
"date"
, field:
"IdentifierDate"
}
}
}
},
});
So when I want to get the total I pass a function to this dataSource (i.e. callback) and return it in the requestEnd event, like so:
requestEnd:
function
(e) {
callback(e);
},
I put this after the schema block in the dataSource, although I don't think it should matter...? This event never fires, or if it does I cannot break inside of it in Chrome. So I tried using the change event in a similar manner, that never fires either. Here's a complete function attempting to get the dataSource and retrieve the total (normally I would not include the events in the dataSource and then bind them again after the dataSource, but for brevity sake...):
GetAssociates:
function
(id, pgSize, callback) {
var
request = {
"SearchParameters"
: {
ID: id
}
};
return
new
kendo.data.DataSource({
transport: {
read: {
type:
"POST"
,
data: request,
cache:
false
,
url: ServiceUri +
"/Associates"
,
dataType:
"json"
}
},
serverPaging:
false
,
pageSize: pgSize,
schema: {
data:
"records"
,
total:
"totalRecordCount"
,
model: {
fields: {
Id: { type:
"number"
},
Name: {type:
"string"
},
Sex: {type:
"string"
},
Race: {type:
"string"
},
Height: {type:
"string"
},
Weight: {type:
"string"
},
Age: {type:
"number"
},
DOB: {type:
"date"
}
}
}
},
requestEnd:
function
(e) {
callback(e);
},
change:
function
(e) {
callback(e);
}
}).bind(
'change'
, callback).bind(
'requestEnd'
, callback);
}
I just want to do a dataSource.total() and find out if there's anything in my dataSource, and I CANNOT. It always returns 0! And I can see that my response is not zero, so why does it always say zero for the total?? I believe I'm following standard async methods to make sure the response has completed, so I'm stumped and completely frustrated, once again.
I know I sound pretty whiny in this message, but it's just been a long day. I sure would appreciate any help!
Thanks,
Eddie