Results 1 to 2 of 2

Thread: How 'v' in GroupSummary plugin populate

  1. #1
    Sencha User
    Join Date
    Jun 2011
    Location
    Chennai, India
    Posts
    17

    Default How 'v' in GroupSummary plugin populate

    I am trying to modify GroupSummary plugin to suit my need. Code for GroupSummary plugin is available in the link below,

    http://trac.symfony-project.org/brow...ry.js?rev=5499

    The plugin has a function to sum up values in a group
    Code:
    'sum' : function(v, record, field){
      return v + (record.data[field]||0);
    }
    I want to sum based on value in another column. So I have written the function below which is adopted from the 'sum'

    Code:
    'sumcredit' : function(v, record, field){
      if (record.data.transtype == 'C') {
      return v + (record.data[field]||0);
      }
    }
    I have give summaryType: 'sumcredit' in the column where I want to display the total. But I get some value which is not correct. But when I give summaryType: 'sum' I am getting proper total.

    So I placed alert (like below) to check how the value of 'v' changes.

    Code:
    'sum' : function(v, record, field){
      alert(v);
      return v + (record.data[field]||0);
    }
    For 'sum' - I was getting 'v' value as zero the first time. Then, I was getting get the cumulative sum.

    For example, if the my values in my column are 100, 150, 50 and 200 the alert message box showed 0, 100, 250, 300... as expected

    But when I used alert in 'sumcredit', I was getting random zeros in between each row's value

    Code:
    'sumcredit' : function(v, record, field){
       alert(v);
      if (record.data.transtype == 'C') {
       return v + (record.data[field]||0);
      }
     }
    Could someone help me understand how the value for 'v' is populated.
    Last edited by Madhu11; 3 Jul 2011 at 8:37 PM. Reason: grammatical mistakes
    When student is ready, teacher appears

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791

    Default

    I'm not familiar with this plugin but it seems to be using the function as an accumulator. Your function won't return a value if transtype isn't 'C', resetting the accumulated value back to 0.

    What about something like this?

    Code:
    'sumcredit' : function(v, record, field) {
        return v + ((record.data.transtype === 'C' && record.data[field]) || 0);
    }

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
  •