1. #1
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    125
    Vote Rating
    0
    Answers
    1
    JavascriptParrot is on a distinguished road

      0  

    Question 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.

    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 
    There is an undefined record in the collection, where does it come from? It screws up the sum function I think.

    Thanks!

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,547
    Vote Rating
    872
    Answers
    3566
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread