Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Send Grid "Summary" Total to CHILD Grid

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Send Grid "Summary" Total to CHILD Grid

    I could use a little help!

    I want to use a column's "Summary Total" in a Child Grid and I'm just not sure of the correct syntax for the "getvalue" Javascript Command.

    Here's what I've done:

    var pObj = {grid.Object}.getParentObject();
    var NewTotal = pObj.getValue('G','PRICE.TOTAL');

    Except that I know that's wrong!

    In the Parent Grid's "OnSummarySectionRender" (Server Side) section, I added this line: NewTotal = e.summaryValues.PRICE.Total, but I don't know how to call that variable from the Child Grid.

    I'm sure I'm just missing something simple and basic, but I'd appreciate if someone can tell me what code I need to use.

    Thanks for your help,
    Phil

    #2
    Re: Send Grid "Summary" Total to CHILD Grid

    normally people will send summary value FROM a child TO a parent (since a single parent will have variable number of child records, and it is easy to get parent object address)
    however, it is little bit more tricky and difficult to send data from parent to the child.
    i think session variables or window objects are best suited for this, since they can float up there and when the child gets rendered it can harvest the data and populate itself.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    [email protected]
    Skype:[email protected]
    1 914 924 5171

    Comment


      #3
      Re: Send Grid "Summary" Total to CHILD Grid

      I don't really need to "send" the data... I just want to be able to ”fetch" it when the user wants to. I'd think it would be easy to get the information from a single parent (e.g. when the user clicks a button). I guess not.

      Comment


        #4
        Re: Send Grid "Summary" Total to CHILD Grid

        in order for a summary value to exist the field where the summary is calculated should be more than one, that is not the usual in a parent and child grid relationship. may be your case scenario is something different. if you can post the structure of the parent and the child someone will be able to figure that out.
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


          #5
          Re: Send Grid "Summary" Total to CHILD Grid

          This seems to be getting more complicated than it should be. The original post sounds fairly straight forward... if I understand it.

          You have a parent grid with a summary value... and a child grid. From the child grid you want to get the parent summary value. Is that right?

          If so, there are at least 2 ways to do this. You're already doing something in onSummarySectionRender... so let's do some more...

          In your parent grid, Server-side Event, onSummarySectionRender

          Code:
          e._state.newTotal = e.summaryValues.PRICE.Total
          session.newTotal = e.summaryValues.PRICE.Total
          Here we are assigning the summary value to both a State variable... and a Session Variable.

          That's all for the parent.

          In the child grid, in order to access session vars from the client-side, we must "publish" those vars. In Grid Properties, find "Published session variables". In here add... in caps...

          Code:
          SESSION.NEWTOTAL
          Now, in any Client-side code... you can do this...

          Code:
          var sessionNewTotal = {grid.Object}.getSessionVariable("NEWTOTAL");

          So... that's one way. The next way involves the State variable we set up. This is more "fun with Javascript" than anything else... but... why not.

          Since we have our summary value in a State variable... we can access that State variable from the Client-side... but, unlike the UX, Grid Client-side State info isn't quite as easy to work with.

          Running this code will re-format and tidy up the State Info...

          Code:
          var pObj = {grid.Object}.getParentObject();
          var parentState = pObj.getStateInfo();
          
          //This is what State Info looks like coming in.
          //"__si2.newTotal=3058.32&__si2.__dtfmt=MM/dd/yyyy&__si2.gridCacheGuid=50fb4aeceab2464bb18e08b6c92723b4&__si2.__gridState="
          
          //The idea is to reformat and clean up this string so that we can parse it into JSON
          
          var psInfo = parentState.replace(/__si2./g,'');
          psInfo = psInfo.replace('&__gridState=','');
          psInfo = psInfo.replace(/=/g,':');
          psInfo = psInfo.replace(/&/g,',');
          psInfo = psInfo.replace(/:/g,':"');
          psInfo = psInfo.replace(/,/g,'",');
          psInfo = '{' + psInfo + '"}';
          
          
          //I found this process here... https://stackoverflow.com/questions/18280279/parsing-malformed-json-in-javascript
          var objKeysRegex = /({|,)(?:\s*)(?:')?([A-Za-z_$\.][A-Za-z0-9_ \-\.$]*)(?:')?(?:\s*):/g;// look for object names
          var newQuotedKeysString = psInfo.replace(objKeysRegex, "$1\"$2\":");// all object names should be double quoted
          var psObject = JSON.parse(newQuotedKeysString);
          
          var newTotal = psObject.newTotal;
          Last edited by Davidk; 06-21-2017, 01:57 AM.

          Comment


            #6
            Re: Send Grid "Summary" Total to CHILD Grid

            OR you could write it down and manually type it into the field you want it, lol - that's my low code solution...
            NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

            Comment


              #7
              Re: Send Grid "Summary" Total to CHILD Grid

              David, Ghandi and Charles... You are amazing. THANK YOU so much for taking your valuable time to respond. I won't lie: Charles' "low-code" solution is the most appealing... I'm just a little worried what my customer will say when I suggest it!

              I was out of the office tonight, so I haven't had a chance to try David's code... to see how it works for me (I'm sure it'll be great). Generally speaking, I'm not crazy about using "session variables" for this type of situation, but the "State Variable" solution looks very promising.

              Also, based on Ghandi's description, I can change the Parent/Child relationship so that the Grid with the Summary Total becomes the "child" and the other Grid becomes the Parent. That gives me an additional approach to the problem.

              I am looking forward to trying the various options to learn which one works best for me.

              Thanks again for your help and suggestions, I'll update you with my final solution.

              Phil

              Comment


                #8
                Re: Send Grid "Summary" Total to CHILD Grid

                I'm not crazy about using "session variables" for this type of situation, but the "State Variable" solution looks very promising.
                some more information as to session and state variables, in case if your are interested.

                https://www.alphasoftware.com/alphaf...hey-equivalent
                Also, based on Ghandi's description, I can change the Parent/Child relationship so that the Grid with the Summary Total becomes the "child" and the other Grid becomes the Parent. That gives me an additional approach to the problem.
                that will be the right approach, since the child grid has the total it can easily get the parent address and update any field easily.
                thanks for reading

                gandhi

                version 11 3381 - 4096
                mysql backend
                http://www.alphawebprogramming.blogspot.com
                [email protected]
                Skype:[email protected]
                1 914 924 5171

                Comment


                  #9
                  Re: Send Grid "Summary" Total to CHILD Grid

                  Hi Ghandi-

                  OK, your suggestion made sense to me so I made the Grid with the "summary total" to Child and the Grid that I want to update to the Parent.

                  In the child grid I added this statement to the "Summary Section" of the Server Side Events: e._state.newTotal = e.summaryValues.PRICE.Total

                  Then, I wanted to add that variable to the Parent Grid after the total was updated by the "Submit" button. So I added this to the Client-Side "After Submit" Event
                  var pObj = {grid.Object}.getParentObject();
                  var myNewTot = e._state.NewTotal;

                  pObj.setValue('G','SUBTOTAL',1,myNewTot);

                  I get an error "can't find variable NewTotal"

                  I'm sure my problem is with the syntax, but I'm not sure what I'm doing wrong. The simple task I'm trying to accomplish is to update the SUBTOTAL field on the Parent Grid with "summary total" of the Child Grid.

                  If you can see what I'm doing wrong, I'd appreciate any guidance you can offer.

                  As always... thanks for your help and your time!

                  Phil

                  Comment


                    #10
                    Re: Send Grid "Summary" Total to CHILD Grid

                    that is not the way to do when sending from child to parent,
                    for some ideas take a look at video M45 in version 11
                    i will try to put a sample code as soon as i can.
                    thanks for reading

                    gandhi

                    version 11 3381 - 4096
                    mysql backend
                    http://www.alphawebprogramming.blogspot.com
                    [email protected]
                    Skype:[email protected]
                    1 914 924 5171

                    Comment


                      #11
                      Re: Send Grid "Summary" Total to CHILD Grid

                      here is a sample code
                      Code:
                      dim total as n
                      total = e.summaryValues.ITEM_AMOUNT.Total
                      dim txt as c
                      txt = "var po = {grid.Object}.getParentObject();"
                      txt = txt + "if (po) { var rn = po._selectedRow;"
                      txt = txt +" po.setValue('G','VENDOR_MINIMUM',rn," + total + ");}"
                      
                      e.javascript = txt
                      this will go in the onSummarySectionRender event,
                      item_amount is the column name in the child - substitute to yours.
                      vendor_minimum is the column name in the parent, substitute to yours.
                      thanks for reading

                      gandhi

                      version 11 3381 - 4096
                      mysql backend
                      http://www.alphawebprogramming.blogspot.com
                      [email protected]
                      Skype:[email protected]
                      1 914 924 5171

                      Comment


                        #12
                        Re: Send Grid "Summary" Total to CHILD Grid

                        If you can see what I'm doing wrong, I'd appreciate any guidance you can offer.
                        please see the link i provided for the difference between these two variables, session and state.
                        then you will know why.
                        thanks for reading

                        gandhi

                        version 11 3381 - 4096
                        mysql backend
                        http://www.alphawebprogramming.blogspot.com
                        [email protected]
                        Skype:[email protected]
                        1 914 924 5171

                        Comment


                          #13
                          Re: Send Grid "Summary" Total to CHILD Grid

                          Hi Ghandi-

                          Well, that just reminds you that "javascript" isn't one of my strengths... I appreciate your teachings! I also learned from the Selwyn's videos that you directed me to.

                          Not surprisingly, your code worked great, exactly what I was asking for (here's the final code I used):
                          dim total as n
                          total = e.summaryValues.PRICE.Total

                          dim txt2 as c
                          txt2 = "var po = {grid.Object}.getParentObject();"
                          txt2 = txt2 + "if (po) { var rn = po._selectedRow;"
                          txt2 = txt2 + "po.setValue('G','SUBTOTAL',rn," + total + ");}"

                          e.javascript = txt2

                          That will work for me. HOWEVER, I have a question: Because the code activates whenever the "summary section" is rendered or changed, the Parent Grid becomes "dirty," even if the user doesn't make any changes (that's why I originally tried putting the code in the client-side "After Submit" event).

                          I tried adding a "conditional" expression to test whether the "summary totals field" was different from the current "SUBTOTAL" field of the Parent Grid. If it were the same, no action would be taken... if it were different (e.g. the user made a change in the Child Grid), then the "setValue" action would occur. Here's one of the variations I tried:
                          dim total as n
                          dim chktotal as n
                          total = e.summaryValues.PRICE.Total

                          dim txt2 as c
                          txt2 = "var po = {grid.Object}.getParentObject();"
                          txt2 = txt2 + "if (po) { var rn = po._selectedRow;"
                          txt2 = txt2 + "var chktotal = po.getValue('G','SUBTOTAL',rn);"
                          txt2 = txt2 + "var ntotal = " + total + ";}"
                          txt2 = txt2 + "if (" + chktotal + " != " + total + ") {po.setValue('G','SUBTOTAL',rn," + total + ");}"

                          e.javascript = txt2

                          No matter what variation I tried, the "setValue" action occurred. I even tried setting a "state" variable for the "summary value" and then put the rest of the code in "AfterUpdateRecord" (Server Side) action, but that didn't work either.

                          This isn't a big deal (I'm just trying to get more skills). I placed a note to the User, to tell him/her that the Parent Grid must be "submitted" EVEN IF no changes are made, so the function will work fine. I'm not sure if this obstacle can be overcome easily, but I wanted to mention it.

                          Once again, Ghandi, you "saved the day", I can't thank you enough for your time. Also, David, I learned a lot from your solution and will surely use it if I need to control a "Child Grid."

                          Thanks to all of you for your help. Have a great weekend.

                          Phil

                          Comment


                            #14
                            Re: Send Grid "Summary" Total to CHILD Grid

                            I placed a note to the User, to tell him/her that the Parent Grid must be "submitted" EVEN IF no changes are made
                            why?
                            you can submit it yourself, why bother them?, and they complain, that's what the users do.
                            use either whole grid submit or just the line submit as in the modified code.
                            Code:
                            dim total as n
                            total = e.summaryValues.PRICE.Total
                            
                            dim txt2 as c
                            txt2 = "var po = {grid.Object}.getParentObject();"
                            txt2 = txt2 + "if (po) { var rn = po._selectedRow;"
                            txt2 = txt2 + "po.setValue('G','SUBTOTAL',rn," + total + ");"
                            txt2 = txt2 + "po.submit();}" 
                            e.javascript = txt2
                            you can also submit that row alone by
                            Code:
                             
                            "txt2 = txt2 + "po.submitGridPartRow(rn);}"
                            Last edited by GGandhi; 06-23-2017, 05:09 AM. Reason: corrected the curly brackets location
                            thanks for reading

                            gandhi

                            version 11 3381 - 4096
                            mysql backend
                            http://www.alphawebprogramming.blogspot.com
                            [email protected]
                            Skype:[email protected]
                            1 914 924 5171

                            Comment


                              #15
                              Re: Send Grid "Summary" Total to CHILD Grid

                              Duh! Now, I'm really embarrassed. I should have thought of that (please don't tell anyone ). That's a great solution!

                              I DID try something similar using a "grid submit" in the SubTotal's "OnChange" event, but I didn't like that for several reasons. This is perfect (FYI, because the Parent Grid is a "totals" section, it will ALWAYS be one line only... the "po.submit()" option in the javascript code will be perfect!

                              I do have a simple question: Why to you do the javascript code as "txt = txt + ..."? Why can't I just add each line ending with a semi-colon (;)? In other words, your code was:
                              dim total as n
                              total = e.summaryValues.PRICE.Total

                              dim txt2 as c
                              txt2 = "var po = {grid.Object}.getParentObject();"
                              txt2 = txt2 + "if (po) { var rn = po._selectedRow;"
                              txt2 = txt2 + "po.setValue('G','SUBTOTAL',rn," + total + ");"
                              txt2 = txt2 + "po.submit();}"
                              e.javascript = txt2

                              Did you do that so that you didn't have to add "e.javascript" to the beginning of each row? Would this have worked:
                              dim total as n
                              total = e.summaryValues.PRICE.Total

                              e.javascript = var po = {grid.Object}.getParentObject();
                              e.javascript = if (po) { var rn = po._selectedRow;
                              e.javascript = po.setValue('G','SUBTOTAL',rn," + total + ");
                              e.javascript = po.submit();}

                              Obviously, your code is cleaner... I was just curious if it could be done another way.

                              Thanks again for all your help. Have a good weekend.

                              Phil

                              Comment

                              Working...
                              X