Results 1 to 2 of 2

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

  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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Answers
    3976
    Vote Rating
    1390
      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
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    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
  •