how to get the sum of a field called amount currently visible on the list view

Hi All,

            I want to get the sum of the a field called amount to be visible on the top of the list view as Total

These should only be for the records which are visible on the sugar.

For example

there is an option to load more record at the bottom on the list view,when we click on it we get the other records and the sum of their amount has also to get calculated and placed on the list view.

Can any one please give a start up for this

Regards Tevfik Tümer

Sidhu

Parents
  • HI Mehul  Bhandari

    This is what i have done previously

    /custom/modules/mymodule/clients/base/views/list-headerpane/list-headerpane.php


    $viewdefs['mymodule']['base']['view']['list-headerpane'] = array(
        'fields' => array(
            array(
                'name' => 'title',
                'type' => 'label',
                'default_value' => 'LBL_MODULE_NAME',
            ),
            array(
                'name' => 'collection-count',
                'type' => 'collection-count',
            ),
            array(
                'name' => 'total',//added by me
            ),
        ),
        'buttons' => array(
            array(
                'name'    => 'create_button',
                'type'    => 'button',
                'label'   => 'LBL_CREATE_BUTTON_LABEL',
                'css_class' => 'btn-primary',
                'acl_action' => 'create',
                'route' => array(
                    'action'=>'create'
                )
            ),
            array(
                'name' => 'sidebar_toggle',
                'type' => 'sidebartoggle',
            ),
        ),
    );

    /custom/modules/mymodule/clients/base/views/list-headerpane/list-headerpane.js


    ({
        extendsFrom: 'HeaderpaneView',
        initialize: function(options) {
            options.meta = _.extend({}, app.metadata.getView(null, 'list-headerpane'), app.metadata.getView(options.module, 'list-headerpane'), options.meta);
            this._super('initialize', [options]);
            app.shortcuts.register('List:Headerpane:Create', 'a', function() {
                var $createButton = this.$('a[name=create_button]');
                if ($createButton.is(':visible') && !$createButton.hasClass('disabled')) {
                    $createButton.get(0).click();
                }
            }, this);
             this.on('render', this.add_total_amount, this);//added by me
        },
        add_total_amount:function()
        {
            
            
            $.ajax({
                    
                        url      : 'getTotal.php',
                        type     : 'POST',
                        data:   {"total":"total"},                        
                        success: function (data)
                        {
                            sum = data;    
                             $('[data-fieldname="total"]').html("<span style='color:green'>Total:R "+sum+"</span>");
                        }
                            
                    });
        
          
          
        },
    })

    But this calculates for the whole records

    I want only the one for which they are available in the list view.

    Regards

    Sidhu

Reply
  • HI Mehul  Bhandari

    This is what i have done previously

    /custom/modules/mymodule/clients/base/views/list-headerpane/list-headerpane.php


    $viewdefs['mymodule']['base']['view']['list-headerpane'] = array(
        'fields' => array(
            array(
                'name' => 'title',
                'type' => 'label',
                'default_value' => 'LBL_MODULE_NAME',
            ),
            array(
                'name' => 'collection-count',
                'type' => 'collection-count',
            ),
            array(
                'name' => 'total',//added by me
            ),
        ),
        'buttons' => array(
            array(
                'name'    => 'create_button',
                'type'    => 'button',
                'label'   => 'LBL_CREATE_BUTTON_LABEL',
                'css_class' => 'btn-primary',
                'acl_action' => 'create',
                'route' => array(
                    'action'=>'create'
                )
            ),
            array(
                'name' => 'sidebar_toggle',
                'type' => 'sidebartoggle',
            ),
        ),
    );

    /custom/modules/mymodule/clients/base/views/list-headerpane/list-headerpane.js


    ({
        extendsFrom: 'HeaderpaneView',
        initialize: function(options) {
            options.meta = _.extend({}, app.metadata.getView(null, 'list-headerpane'), app.metadata.getView(options.module, 'list-headerpane'), options.meta);
            this._super('initialize', [options]);
            app.shortcuts.register('List:Headerpane:Create', 'a', function() {
                var $createButton = this.$('a[name=create_button]');
                if ($createButton.is(':visible') && !$createButton.hasClass('disabled')) {
                    $createButton.get(0).click();
                }
            }, this);
             this.on('render', this.add_total_amount, this);//added by me
        },
        add_total_amount:function()
        {
            
            
            $.ajax({
                    
                        url      : 'getTotal.php',
                        type     : 'POST',
                        data:   {"total":"total"},                        
                        success: function (data)
                        {
                            sum = data;    
                             $('[data-fieldname="total"]').html("<span style='color:green'>Total:R "+sum+"</span>");
                        }
                            
                    });
        
          
          
        },
    })

    But this calculates for the whole records

    I want only the one for which they are available in the list view.

    Regards

    Sidhu

Children