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
    Vote Rating

    Question 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){
    //i {phantom: true, internalId: "ext-record-39", raw: Object, data: Object, modified: Object} 
    There is an undefined record in the collection, where does it come from? It screws up the sum function I think.


  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    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!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2

    Think my support is good? Get more personalized support via a support subscription.

    Need more help with your app? Hire Sencha Services

    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.

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