Aggregate values for columns

Trevor DeVore lists at mangomultimedia.com
Tue Jun 23 16:24:19 EDT 2009


On Jun 23, 2009, at 10:10 AM, Josep wrote:

> The code is:
>
> On FillInData
>
> ...
> <Perform some Col operations>
> ...
>
> ...
>
> end FillInData
>
> I need calculate the amounts for the taxes. When the users insert a  
> item I
> need calculate the total for the line. Multiply units by product  
> cost, and
> update the total for the document with her taxes.
> I have three posibles taxes. After call uSumTotal for the col that  
> have the
> totals, I perform some others operations and fill the fields.
>
> The question is if this is correct to do in FillInData, in your last  
> post
> you confirm that is the good place, and what effect can have in the
> performance of the datagrid or the stack.

FillInData is a good place to perform cell specific actions but not  
column specific actions as you will be performing the column  
calculations way more often then is needed.

If I understand correctly you just need to make sure the aggregate  
values stay up to date:

1) After you draw the data grid for the first time.

2) When the user updates values in a cell.

If the above is true then I would add a handler to my card script  
called something like "UpdateAggregateFields". This handler would  
perform all of the code that you currently have in FillInData that  
isn't cell specific.

You can then call this handler after (1) or (2) occurs. You can deal  
with (2) by handling the CloseFieldEditor message. The quickest way to  
do what you want to is something like this:

on CloseFieldEditor pFieldEditor
     ## save the data to dgData array before upating aggregate fields
     SetDataOfIndex the dgIndex of me, the dgColumn of me, the text of  
pFieldEditor

     ## Update aggregate columns.
     UpdateAggregateFields
end CloseFieldEditor

Make sense?

Additional details on field editors are available in this chapter of  
the manual:

Using the Built-In Field Editor
<http://revolution.screenstepslive.com/spaces/revolution_tools/manuals/datagrid/chapters/1536 
 >

Regards,

-- 
Trevor DeVore
Blue Mango Learning Systems
www.bluemangolearning.com    -    www.screensteps.com



More information about the use-livecode mailing list