Page 1 of 1

new to Polygrid

Posted: Fri Oct 13, 2023 2:38 pm
by lemodizon
Hi everyone,

good day

I bought a widget polygrid from livecode.

This is my first time to use this widget can some one teach me how to get the total sum in one column.

sorry for my code if they are long codes for you i'm still trying and learning to make it short.

Code: Select all

on checkData
   if fld "fldQtty" is empty or hilitedbutton of grp "grpType" is 0 or hilitedbutton of grp "grpLoc" is 0 then
      beep
      Answer error "May nakalimutan ka ilagay pa." titled "Error: May nakalimutan ilagay"
   else
      put fld "fldQtty" into tQtty
      
      if the hilite of btn "Round" then 
         put "Round" into tType
      end if
      
      if the hilite of btn "Slim" then 
         put "Slim" into tType
      end if
      
      if the hilite of btn "Clark" then
         put "Clark" into tLoc
      end if
      
      if the hilite of btn "Sapangbato" then 
         put "Sapangbato" into tLoc
      end if
      
      if the hilite of btn "WalkIn" then 
         put "Walk-IN" into tLoc
      end if
      
      put tQtty &TAB& tType &TAB& tLoc &TAB& short Time &TAB& short Date into tNewInputData
      put the pgText of widget "PgridGallon" of stack "StackGallons" into tOldData
      
      if tOldData is empty then
         put tNewInputData into tOldData
      else
         put cr & tNewInputData after tOldData
      end if
      set the pgText of widget "PgridGallon" of stack "StackGallons" to tOldData
   end if
   
   repeat for each key tkey in tOldData // i just got this code  from the dictionary
   put tOldData [tkey]["cQtty"] into tQtty
   
   // i'm stuck here I don't what's next code 
    
end checkData


this past days i tried using field and repeat to get the sum thanks for those who share their knowledge in that topic.

Re: new to Polygrid

Posted: Fri Oct 13, 2023 3:28 pm
by Klaus
Maybe this is what you are missing:

Code: Select all

...
repeat for each key tkey in tOldData // i just got this code  from the dictionary
   put tOldData [tkey]["cQtty"] into tQtty
   add tQtty to tTotalSum
end repeat
...
I'm not sure WHERE exactly you want to display the tTotalSum in the end?

Re: new to Polygrid

Posted: Fri Oct 13, 2023 4:25 pm
by cpuandnet
Hi Lemodizon,

Looking at your code, keep in mind that you are using pgText not pgData. With pgText, think lines and items not arrays, elements and keys like you would with pgData. So, in lieu of that I would use something like this, assuming that the quantity column is the first column and you have no invisible columns before it:

Code: Select all

   set itemDelimiter to tab
   repeat with tLineNo = 1 to the number of lines of tOldData
      add item 1 of line tLineNo of tOldData to tSumTotal
   end repeat
I hope this helps.

Tim

Re: new to Polygrid

Posted: Fri Oct 13, 2023 4:42 pm
by Klaus
Ouch, totally overlooked this, of course you are right!

Re: new to Polygrid

Posted: Sat Oct 14, 2023 12:16 pm
by lemodizon
Hi Tim & klaus,

thank you for helping me out. I appreciate your help guys.

Which one is better polygrid or datagrid?

Re: new to Polygrid

Posted: Sat Oct 14, 2023 1:02 pm
by Klaus
It depends... 8)

Re: new to Polygrid

Posted: Sat Oct 14, 2023 2:15 pm
by Klaus
I would say a PolyGrid is easier to create and manage, but a datagrid is a bit more powerful but has also a very steep leraning curve!
E.g. the user can modify text by doubleclicking a cell in a Datagrid (if the programmer allows), that is not possible with a PolyGrid.

Re: new to Polygrid

Posted: Sat Oct 14, 2023 3:25 pm
by lemodizon
Hi Klaus,

Thanks. how do you sort in polygrid? i can't find in the property inspector. While in data grid property inspector it is available.

i tried this code nothing happens in my polygrid.

Code: Select all


sort lines of tOldData descending numeric by item 1 of each 

Re: new to Polygrid

Posted: Sat Oct 14, 2023 3:33 pm
by cpuandnet
As Klaus indicated, the polygrid is easier. Start with the polygrid and see if that fills your requirements. If not, then you can move to the datagrid. The datagrid is very powerful but can also be a bit fussy or slow at times so you really need to experiment in your learning process of the datagrid.

On you sorting, did you set the pgText of the polygrid with tOldData?

Tim

Re: new to Polygrid

Posted: Sat Oct 14, 2023 3:46 pm
by Klaus
Hi lemodizon
lemodizon wrote:
Sat Oct 14, 2023 3:25 pm
...
i tried this code nothing happens in my polygrid.

Code: Select all

sort lines of tOldData descending numeric by item 1 of each 
well, that will sort the lines of the VARIABLE tOldData! :-)
As Tim stated, you then also need to:

Code: Select all

set the pgText of widget "your polygrid" to tOldData
again!

Best

Klaus

Re: new to Polygrid

Posted: Sat Oct 14, 2023 6:24 pm
by Klaus
FYI:
Here is a comparison of Datagrid <-> PolyGrid in a LC blog https://livecode.com/datagrid-vs-polygrid-head-to-head/

Re: new to Polygrid

Posted: Mon Oct 16, 2023 12:00 pm
by lemodizon
Hi Klaus,

Thanks again I really appreciate your help.

Re: new to Polygrid

Posted: Mon Oct 16, 2023 12:07 pm
by Klaus
It was Tim who gave the final clue! ;-)

Re: new to Polygrid

Posted: Mon Oct 16, 2023 12:58 pm
by lemodizon
Thanks Tim and Klaus :)