Sum column of a data grid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
cbarbal
Posts: 102
Joined: Fri May 08, 2015 5:04 pm

Sum column of a data grid

Post by cbarbal » Sat Nov 03, 2018 5:40 pm

Hi,

I just did the lesson "How Do I Get Aggregate Values for Columns?", Which calculates the total by a button. I would like it to be done automatically when the data grid is filled, without using the button. It's possible?

Thanks in advance,

Carles

bogs
Posts: 2382
Joined: Sat Feb 25, 2017 10:45 pm

Re: Sum column of a data grid

Post by bogs » Sat Nov 03, 2018 6:10 pm

I am sure it is possible, although I am no expert with the datagrid. Some things you *might* try -

Take your code out of the button and put it in another message path, like the dg group handler 'closeControl', which I believe triggers when you leave the grid.

Depending on how you navigate the grid, you can make your own handler, and trigger the code currently in the button by moving it to your handler.

Lets say you use the 'tab' key to move through the grid. You want your column to auto sum up on every tab key, so you might put in the dg script -

Code: Select all

on tabKey
	myHandler
end tabKey
Down in the card or stack script, your handler would get the button script, which would be activated anytime the tab key is pressed from the dg group.

*Edit for clarity -
You could put the button script into the tabKey handler directly, the reason I suggested writing out the separate handler is because you could be navigating the grid in any number of ways, instead of repeatedly pasting the script into each one, you write the handler once and refer to it in every way you can / will allow the navigation.

I'm sure someone with a lot more familiarity with the dg will chime in shortly.
Last edited by bogs on Sat Nov 03, 2018 6:18 pm, edited 1 time in total.
Image

Klaus
Posts: 10486
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sum column of a data grid

Post by Klaus » Sat Nov 03, 2018 6:12 pm

Hola Carles,

sure, put the handler under a new name (maybe "your_calculation" instead of "mouseup") into the card or even stack script and execute it right after you have filled your datagrid.

Code: Select all

...
set the dgtext of grp "your datagrid here" to whatever_variable
## Do your calculation here
your_calculation
... 
Best

Klaus

cbarbal
Posts: 102
Joined: Fri May 08, 2015 5:04 pm

Re: Sum column of a data grid

Post by cbarbal » Sat Nov 03, 2018 6:45 pm

Thank you very much, bogs and Klaus for the answers.

In the script that loads the data grid have added the text of the script of the button and it does it automatically.

Regards,

Carles

bogs
Posts: 2382
Joined: Sat Feb 25, 2017 10:45 pm

Re: Sum column of a data grid

Post by bogs » Sat Nov 03, 2018 7:09 pm

Yes, that would work too, but don't you need the totals updated as the program runs along? In any case, glad you figured it out :)
Image

cbarbal
Posts: 102
Joined: Fri May 08, 2015 5:04 pm

Re: Sum column of a data grid

Post by cbarbal » Sat Nov 03, 2018 7:57 pm

Hi bogs,

Not at the beginning. The data grid is filled with the revenues, expenses and the annual balance that are in other SQL tables. Each time I select a row of the "mother" data grid, I fill in the data in another data grid that executes the script that recalculates it.

Regards,

Carles

bogs
Posts: 2382
Joined: Sat Feb 25, 2017 10:45 pm

Re: Sum column of a data grid

Post by bogs » Sat Nov 03, 2018 9:16 pm

Ahh, I get it :)
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”