Basket help

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: FourthWorld, heatherlaine, Klaus, kevinmiller

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Basket help

Post by sturgis » Sun May 08, 2016 7:09 pm

Edit: so much for the pics.
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: Image (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.
Image

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
Remove the line that says "set the text of field 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
You should also look for the "Layoutcontrol" handler and have it set the rect of btn 1 of me rather than the rect of field 1 of me,since we're working with the button in the custom template.


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"]
Since i'm assuming numbers only in your data, you can add your monetary sign to the display pretty simply. Change the above set line to.

Code: Select all

   set the text of field 1 of me to "$" & theDataA["cost"] * theDataA["quantity"]
[/code]
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!

AzTheBest
Posts: 25
Joined: Wed May 04, 2016 2:19 pm

Re: Basket help

Post by AzTheBest » Mon May 09, 2016 12:56 am

hey man ive been trying to so much but keep on failing or keep getting script error! as sometimes i dnt get "custom behavoiur" button and when i do i did everything then i messed up the code or misuderstood it! ive deleting the table and doing it all over mutiple times and failed annoyingly :(
could u do it for me and send me a template here please

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Basket help

Post by sturgis » Mon May 09, 2016 4:36 am

https://www.dropbox.com/s/btro3ye1rxjvx ... ecode?dl=0

There are 3 custom columns in the linked stack above. Cost has a behavior script that prepends the monetary symbol to the cost. Don't include the symbol in the data you use to set the datagrid.

The quantity behavior.. well, look at it and read the script for that and for total. The Total behavior also prepends the currency symbol.

AzTheBest
Posts: 25
Joined: Wed May 04, 2016 2:19 pm

Re: Basket help

Post by AzTheBest » Mon May 09, 2016 5:46 pm

hey man thank you but why does it keep doing this? i clicked the "chicken button" and it did all this?....
Attachments
what.png

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Basket help

Post by sturgis » Mon May 09, 2016 6:50 pm

change your chicken button so that it puts "5" into the array for cost. (no currency symbol)

In the message box, type "set the dgdata of grp "yourdatagrid" to empty.

click the chicken button.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Basket help

Post by sturgis » Mon May 09, 2016 7:02 pm

Have you considered using something other than the datagrid for your display?

AzTheBest
Posts: 25
Joined: Wed May 04, 2016 2:19 pm

Re: Basket help

Post by AzTheBest » Mon May 09, 2016 8:21 pm

i dnt get any error but it fills up the whole table annoyingly

what do you mean? do u have any other suggestion i could use instead of a data grid?

AzTheBest
Posts: 25
Joined: Wed May 04, 2016 2:19 pm

Re: Basket help

Post by AzTheBest » Mon May 09, 2016 8:40 pm

In the message box, type "set the dgdata of grp "yourdatagrid" to empty.

i did that code however now i cant click the "chicken button" mutiple times to make a list going down it keeps deleting and refreshing the table

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Basket help

Post by sturgis » Mon May 09, 2016 8:45 pm

Yeah. Any of the number of available fields. The entry level of knowledge for the datagrid is pretty high, it might be easier to just use a regular old field, or table field, or scrolling list field or....

Livecode is really good at processing text. It should be relatively simple to use a text field of some type for your display. It'll help you get the hang of chunking, using before, after, into..

What is the script in your chicken button?

AzTheBest
Posts: 25
Joined: Wed May 04, 2016 2:19 pm

Re: Basket help

Post by AzTheBest » Mon May 09, 2016 9:09 pm

Code: Select all

  set the dgdata of grp "main" to empty
   
   put "Chicken" into theDataA["Main Menu"]
   
   
   put "5" into theDataA["Cost"]
   

put  1 into theLineNo

dispatch "addData" to group "main" of card "8" of stack "Restraunt Template" with theDataA,theLineNo


put the result into theNewIndex

thats the code

yea but i mean if i can do this then im pretty much close finishing the app
plus i dnt know understand how text feild and stuff work for making a reciept

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Basket help

Post by sturgis » Mon May 09, 2016 9:57 pm

Your button keeps using 1 as theLineNo rather than getting the current number of records in the datagrid, adding 1, and using that to insert the new record.

I don't have time to look it up again, but I think if you go back to one of the previous posts in this thread, I gave code that will do that. (look for dgNumberofRecords or something like that)

THe dg is just quirky it seems. I keep having to do strange things (that I shouldn't have to) to keep it working.

For example. Adding an item works fine. But the option button to change quanitity doesn't always respond. But then setting the dgdata of the group to the dgdata of the group fixes it.

If you are curious, I have a very quick and dirty example of the same sort of thing using a field instead of a datagrid. Its here. https://www.dropbox.com/s/79ranbl71bkhx ... ecode?dl=0

AzTheBest
Posts: 25
Joined: Wed May 04, 2016 2:19 pm

Re: Basket help

Post by AzTheBest » Mon May 09, 2016 10:07 pm

hey man thanks i kinda like this however is it possible not to get the blue line for example after 1 interval each it highlghts it blue?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Basket help

Post by sturgis » Mon May 09, 2016 10:11 pm

Look in the card script. There is a command "addItem"

Find the "If" block that sets the background color for even lines and remove the whole block.

AzTheBest
Posts: 25
Joined: Wed May 04, 2016 2:19 pm

Re: Basket help

Post by AzTheBest » Sat Jun 18, 2016 5:07 pm

hi can anyone help me with a code i cant seem to find one or im not doing it right

i have a button which sends data into table which is in stack 8

However i have copied the button and code from stack 8

in stack 1. i have copied the button from stack 8 (note:the table is in stack 8)
and when i click it! i keep getting error?
is there a code to dispatch the info from one stack to another stack containing the table?

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

Re: Basket help

Post by Klaus » Sat Jun 18, 2016 5:30 pm

Can you please post the script(s) here?
Guessing is just too ineffective :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”