1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    4
    Vote Rating
    0
    ashimmohanty is on a distinguished road

      0  

    Default Adding a new Row wth dynamic values

    Adding a new Row wth dynamic values


    I want to add a Row which would show the sum of all the values prior to it.
    How can I do that ?Really dont know what to do....
    Ex:

    aaa val1 val2
    aaa 12 23
    aaa 23 45
    Total 35 68
    bbb 10 16
    bbb 16 10
    Total 26 26


  2. #2
    Sencha User
    Join Date
    Mar 2012
    Posts
    4
    Vote Rating
    0
    ashimmohanty is on a distinguished road

      0  

    Default


    I want to render it from the server side only..I am getting the values of individual datas..i just want to render another row which would show their sum...

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    20
    Vote Rating
    0
    narram123 is on a distinguished road

      0  

    Default try this

    try this


    Hi,

    When you get the response from server, loop thro the corresponding dataIndex and keep

    adding the sum.Add a value to the store which contains the sum. It should work.

  4. #4
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default use store.insert

    use store.insert


    Add load event listener to your store, so we can start process when store loads:

    Code:
    var store = new Ext.data.JsonStore({
    ..... listeners: {
    load: function(store, records, options){
    var total = 0, rowValue = 0, totalRowRecord;
    for(var i = 0, len = records.length; i < len; i++){
    rowValue = parseInt(records[i].get('value'));
    rowValue = !isNaN(rowValue) ? rowValue : 0;
    if(((i + 1) % 5 === 0) || ((len % 5) > 0 && i === len - 1)){ //for each 5 records or for the last record show total row
    total += rowValue;
    totalRowRecord = new (store.reader.recordType)({ name: 'Total', value: total });
    store.insert(i, totalRowRecord); //insert total row total = 0; //set 0 again
    } else {
    total += rowValue;
    }
    }
    }
    }
    });
    This would probably work, give it a try!

    Regards.
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

Thread Participants: 2