Results 1 to 2 of 2

Thread: Store.query, .sum gives NaN, .each give 1 row too many

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    125
    Answers
    1
    Vote Rating
    1
      0  

    Question 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •