Edit: fixed the pics
Ok. Here is a very basic walkthrough.
Create a new datagrid. Name it as needed using the property inspector.
Create your columns in the property inspector.
Choose your "Quantity" column in the columns pane of the property inspector.
Click the "+" button to create a custom column template. Hopefully it will actually work.
If it DOES work, it will pop up a group editing window that looks like this: (hopefully the image will show.)
Select the template line (the grey area, make sure you don't have "select grouped" turned on)
then click "edit group" on the main bar.
Delete the field that says "quantity"
Add in your dropdown button, of whatever style you prefer (I chose an option button) and place it generally where it belongs. Not really that important where.
Since you want to have choices 1 to 10, change the list of options in the property inspector from Choice 1 choice 2 etc. to 1 through 10, 1 per line. It doesn't hurt to name the button "quantity" but isn't really necessary.
Click to stop editing the group.
Click the x to close the template editing window from the above picture.
It will ask if you want to save the template stack, say yes.
Next, back in the property inspector for the group, in the columns tab, choose your total column.
Click the "+" button once to add a custom column template for that column.
A template window should pop up again. It's been a while since I've done this, but in version 8, it will probably show both the button you just added, and a text field. Thats fine, nothing needs to be done, the text field that is there for the total column already is fine.
Close the window, if it asks to save, say yes.
Now, back to the property inspector for the datagrid. Again choose the "quantity" column.
This time click "column behavior" and it should open a scripting window. For me it did NOT. (the behavior seems to have not been set, ignore the next parts if it worked for you,otherwise read on)
To fix this, I had to go to the project browser.
I expanded the datagrid templates stack
I expanded the second card (card id 2005)
I expanded the "row template" section.
Then I chose the "quantity" button. (since I named it that)
There is also the "label" field that i used for the total custom column template in there. Here is an image showing it I hope.
I then right clicked the "quantity" button and chose "property inspector"
In the property inspector for btn "quantity" I went to the advanced pane.
It should have a box for the behavior.
If you click the circular button to the right that looks like a target, it will let you pick the source for your behavior. Unfortunately, it will probably only show the controls from your main stack rather than the datagrid template stack. If this is the case for you, go back to the project browser and double click the datagrid template stack. This will re-open the "editing template" window. Guess I should have left it open before eh?
Try setting the behavior of that button again.
With the "editing template" stack active (as the current stack) it should show very few controls that can be used as the behavior. Choose "quantity behavior"
TA DA!
Now, close the editing template, yes to save if it asks.
Go back into the property inspector for the datagrid, choose the quantity column, click the "Column Behavior" button,and it should open the script window.
In the script for the quantity behavior, find at the very top the "fillNData" handler
If you have set data that includes a "quantity" key, you can simply..
"set the label of btn "quantity" of me to pData
If you aren't setting an initial value with your data, you'll want to account for that.
Code: Select all
-- if data for quantity is empty then
if pData is empty then
-- get the data for the row
put the dgDataOfIndex[ the dgIndex of me] of the dgControl of me into theDataA
-- set the value of quantity to 1
put 1 into theDataA["quantity"]
-- updata the row in the datagrid
set the dgDataOfIndex[the dgindex of me] of the dgcontrol of me to theDataA
end if
-- set the value of the option buttons label to the value stored in the datagrid for this row
set the label of btn 1 of me to pdata
Since you need to be able to change the data in the datagrid with the option button, you'll need to add a mouseup handler also.
In the behavior script for the quantity button, add a mouseup handler that looks like this.
Code: Select all
on mouseup pbtn
-- only do this when its the leftmouse btn.
if pbtn is 1 then
-- grab the data for the row
put the dgDataOfIndex[ the dgIndex of me] of the dgControl of me into theDataA
-- get the newly set label for the button and put it into the array for the row
put the label of btn 1 of me into theDataA["quantity"]
-- set the row to the updated data including the changed quantity
set the dgDataOfIndex[the dgindex of me] of the dgcontrol of me to theDataA
end if
end mouseup
compile that script,then try adding sample data to your datagrid and make sure it works.
I would recommend NOT using monetary signs as part of your data. That way you don't have to jump through a ton of hoops to get things done. (well ok, there are hoops either way. If you put a $ or whatever in your data, you need to process the text to extract the number when doing calculations. If you don't, you need a custom template for cost that pre-pends a monetary sign when its displayed) In the examples below , the assumption is made that "cost" is a number.
Moving on to the behavior for totals.. If it doesn't seem to have a behavior attached, do as before and fix it if you can. (it worked for me)
In the properties inspector for the datagrid, choose the total column. Click "column behavior" to open the script window.
find the "fillinData" handler and make it look like so..
Code: Select all
-- grab the data for the row so we can work with it and put it into an array
put the dgDataOfIndex[ the dgIndex of me] of the dgControl of me into theDataA
-- set the text of field 1 to the result of the math.. thedataA["cost"] * theDataA["quantity"]
set the text of field 1 of me to theDataA["cost"] * theDataA["quantity"]
Code: Select all
set the text of field 1 of me to "$" & theDataA["cost"] * theDataA["quantity"]
Using your sign of course. This puts the sign & the resutls of the calc into the field. you might also look at numberformat in the dictionary too"
If a monetary sign is part of your data then you would have to break out the number portion.
set the text of field 1 of me to char 1 of theDataA["cost"] & (char 2 to -1 of theDataA["cost"] * theDataA["quantity"]
Much just depends on how you want to handle things. (I guess this is no more difficult than adding another custom template for "cost" that handles adding your monetary sign, so /shrug. ) Its up to you.
Sorry this is so long and complicated, since I did run into trouble, I made sure to include how I got around the issue. hopefully you won't have the same troubles.
Good luck. and read LOTS!