Calculating total all pages dynamically with search

Hi guys,

i have a problem,

i want to calculate my custom field on accounts module and i want it can calculate all of the page when i use search too

i have customize the code, but it just calculate 20 list (shown on the page only) of data per page, not all page

how i can do that ?


How are you doing this? Can you post the code that you are using?

Hi andy,

i just do the step by step from here Sugarcrm

but it just calculate 20 data in each page.

Yes because you are using the process record logic hook which only fires on each record that is being displayed.

Get rid of the function sumTotalFromEachRow as you don’t need this. and try something like:

     * Called as a after_ui_frame logic hook on the Opportunities module
    public function displaySumTotal($event, $arguments)
        if ($GLOBALS['action'] == 'index' || $GLOBALS['action'] == 'ListView') {
	$opportunity = new Opportunity();
                    $opportunites = $opportunity->get_full_list();

                    foreach($opportunites as $opp){
                        self::$sum += $opp->amount_usdollar;

                    $sum = currency_format_number(self::$sum);

            echo <<<EOHTML
<script type="text/javascript">
$('<p>Total Amount is {$sum}</p>').insertAfter('.moduleTitle');

Oh I see you want to do it with the search results, my previous post just shows you how to do it with all the records. Getting it to work with search is more complicated.

Hi andy, thanks for your advice

i have tried your code, but its still calculate each record that is being displayed.

or should i edit or add some code on this?

public function sumTotalFromEachRow($bean, $event, $arguments)
        self::$sum += $bean->amount_usdollar;



its works now

and for the search , any advice for it?


Maybe so :

Make this for see if we can retrieve de used query.

var_dump($_REQUEST) or var_dump($this)

If you see the used query, you can do wath you wil with string manipulation.


i want to make a dynamic sum of field

for example on ex1.jpg

when i use search with a condition , the total list is 21 data then i just want to sum 21 data , at the bottom of list view just displayed sum of 20 data (showed data)

but on the bottom left of list view sum all of data (more than 21 data)

on ex2.jpg

i search using different condition
its still display sum of all data.

can anyone help my problem?