-
9 Nov 2012 7:49 AM #1
Unanswered: Store.query, .sum gives NaN, .each give 1 row too many
Unanswered: Store.query, .sum gives NaN, .each give 1 row too many
Hello all,
I have a store with some records and fields that are summed, I use the Sum function to get the total of the field Quantity. Next I need to know the total of the records where a property is set to true. There is one row at this time that meet this filter. I use the query function to retrieve the row(s), but when using the sum function it gives me NaN, using the each function it gives me two records? But the last record is undefined, here some code to explain.
There is an undefined record in the collection, where does it come from? It screws up the sum function I think.PHP Code:var quantityTotal = ArtStore.sum("Quantity"); //is 500
var FilteredRecords = ArtStore.query("field", true);
//FilteredRecords.length = 1
//FilteredRecords.sum("Quantity") = NaN
FilteredRecords.each( function(rec){
console.log(rec);
});
//i {phantom: true, internalId: "ext-record-39", raw: Object, data: Object, modified: Object…}
//undefined
Thanks!
-
14 Nov 2012 10:45 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3160
Since you are doing two "sums" I would just iterate through the store with store.each and have a couple variables to add to based on the values of the fields.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote