1. #1
    Sencha User
    Join Date
    Jun 2010
    Posts
    18
    Vote Rating
    0
    shadow_m is on a distinguished road

      0  

    Default Grid summary plugin: problem with summaryType: sum

    Grid summary plugin: problem with summaryType: sum


    Hi!
    I have a problem with Grid Summary plugin.

    My grid has 3 columns: 1) count 2) price 3) Sum

    Sum column has a renderer:
    Code:
    {
     xtype: 'gridcolumn',
     dataIndex: 'cost',
     text: 'Сума',
     renderer: function(v, params, record)  { 
     return '<span style="color:blue;"> '+ record.data.price * record.data.count + ' </span>';
     }
    },
    I am trying to use summaryType: 'sum', but it show "0" instead of real value.
    How can I fix it?
    Thanks

  2. #2
    Sencha User
    Join Date
    Aug 2011
    Posts
    2
    Vote Rating
    0
    draganica is on a distinguished road

      0  

    Default


    Najbolje da napravis custom funkciju summaryType: function(){} pa da ona uradi sumiranje

  3. #3
    Sencha User
    Join Date
    Jun 2010
    Posts
    18
    Vote Rating
    0
    shadow_m is on a distinguished road

      0  

    Default


    Can anybody help me with this?

  4. #4
    Sencha User
    Join Date
    Aug 2011
    Posts
    2
    Vote Rating
    0
    draganica is on a distinguished road

      0  

    Default


    try using custom summary function
    Code:
    summaryType: function(){....}
    see in docs about params or use console.log(arguments) to find params that function uses
    u can make custom summaryRenderer function also, see docs

  5. #5
    Sencha User
    Join Date
    Mar 2011
    Posts
    2
    Vote Rating
    0
    Viorel is on a distinguished road

      0  

    Default


    fixed for me
    Code:
    var w = 0;
    Ext.define('AM.view.grid.BudgetGrid' ,{
        extend: 'Ext.grid.Panel',
        alias: 'widget.budgetGrid',
        id: 'budgetGrid',
        store: 'StoreBudgetGrid',
        title: 'Buget',
        
        initComponent: function() {
            this.columns = [
                {xtype: 'rownumberer',flex: 1},
                {header: 'Denumire',dataIndex:'denum',flex: 8, summaryType: 'count'},
                {header: 'Subcategorie', dataIndex: 'cild', flex: 4},
                {header: 'Data', dataIndex: 'data', flex: 3, renderer: Ext.util.Format.dateRenderer("d.m.Y")},
                {header: 'Suma', flex: 3, dataIndex: 'suma',
                    summaryType:  function(){
                        var store = Ext.getStore('StoreBudgetGrid');
                        var records = store.data.items;
                        var field = ['suma'];
                        function Suma(record, field) {
                            var total = 0;
                            var j = 0,
                            lenn = record.length;
                            for (; j < lenn; ++j) {
                               total = total + parseFloat(record[j].get(field));
                            }
                            return total.toFixed(2);
                        };
                        if (this.isGrouped()) {
                            var groups = this.getGroups();
                            var i = 0;
                            var len = groups.length;
                            var out = {},
                            group;
                            for (; i < len; i++) {
                                group = groups[i];
                                out[group.name] = Suma.apply(store, [group.children].concat(field));
                            }
                            var groupSum = out[groups[w].name];
                            w++;
                            return groupSum;
                        } else {
                            return Suma.apply(store, [records].concat(field));
                        }
                    },
                    summaryRenderer: function(value, summaryData, dataIndex) {
                        return '<b>' + value + '</b>';
                    }
                }
            ],
            this.features = [{
                groupHeaderTpl: 'Subject: {name}',
                ftype: 'groupingsummary',
                hideGroupedHeader: true,
                enableGroupingMenu: false
            }],
    
    
            this.callParent(arguments);
    	}
    });

Thread Participants: 2