1 2 Previous Next 16 Replies Latest reply on Jan 21, 2010 5:30 PM by eX-Christo

    sorting portal rows with drag and drop functionality

    johnhorner

      Title

      sorting portal rows with drag and drop functionality

      Post

      i recently came across a demo file that had the ability to sort portal rows using a drag and drop style method.  it relied on a short script (the script is also copied below if needed) which is triggered when you enter the field ("handle") in the portal row and then relied on an auto-enter calculation in the same field ("handle") which was as follows:

       

      Let ( [
      _trigger = handle ;
      _sortdown = Get ( ScriptParameter ) > sort ;
      $$sort_id = id ;
      $$slide_down = ase ( IsEmpty ( Sort LOWER::sort ) ; sort – 1 ; ( sort + Sort LOWER::sort ) / 2 ) ;
      $$slide_up = Case ( IsEmpty ( Sort HIGHER::sort ) ; sort + 1 ; ( sort + Sort HIGHER::sort ) / 2 )
      ]; Main::gGraphics [ 6 ] )

       

      i am trying to understand how this works.  i have 3 questions about this function:

       

      1.  what is "_trigger"?  i don't see it referenced anywhere else in the file as a field, a variable, a script name or a table occurrence.  is it a variable?  don't variables have to begin with either "$" or "$$"?

      2.  what is "_sortdown?  (same issues as above for "_trigge

      3.  finally, i don't understand how the line "_sortdown = Get ( ScriptParameter ) > sort" works.  how you can use a "Get(ScriptParameter)

        3a.   how you can use a "Get(ScriptParameter)" when this is not in a script (it is in an auto-enter calculation).

        3b.  assuming that "_sortdown" is a variable for the sake of this particular question, what does it mean to set a variable equal to something ">" (greater than) something else? for example, if the script parameter was "3" and sort was "5" how can a variable = 3>5?

       

      i know these are probably really stupid questions, but despite many hours trying to figure this out, i am at a loss.  any help would be much appreciated.  thanks!

       

      p.s. here is the script:

       

      If [ Sort::id <> $$sort_id and not IsEmpty ( $$sort_id ) ]

          Set Field [ Sort::sort; Case ( Sort::sort > $$slide_down ; $$slide_down ; $$slide_up ) ]
      End If

      Commit Records/Requests

      Set Variable [ $$sort_id; Value:"" ]




        • 1. Re: sorting portal rows with drag and drop functionality
          comment_1
            

          1&2. These are variables defined using the Let() function - see the help on this function for more.

           

          3a. A calculation evaluated while a script is running can access the script's parameter.

           

          3b. The expression "Get ( ScriptParameter ) > sort" returns either true (1) or false (0).

          • 2. Re: sorting portal rows with drag and drop functionality
            johnhorner
               thanks comment!  as you can tell... i still have a lot to learn!
            • 3. Re: sorting portal rows with drag and drop functionality
              RickWhitelaw
                

              Comment wrote:

               

              "1&2. These are variables defined using the Let() function"

               

              I see these variables defined but don't see why . . . they're not used in the calculation part. . . . ?

               

              RW 

              • 4. Re: sorting portal rows with drag and drop functionality
                comment_1
                  

                I am guessing the first one is used to reference a field, so that the calculation re-evaluates when the field is modified. At least that's how I use a variable named "trigger":

                http://forum-en.filemaker.com/fm/board/message?board.id=FM-en-4&message.id=34270#M34270

                 

                I don't know about the second one.

                • 5. Re: sorting portal rows with drag and drop functionality
                  RickWhitelaw
                    

                  Comment,

                   

                  Thanks. The post you cited was a reply to me asking the same question a while ago . . . doh! I assume "trigger" is meant to be literally referenced elsewhere as a variable. Otherwise FM wouldn't recognize it, correct? "Trigger" as an expression has no special significance in FM?

                   

                  RW 

                  • 6. Re: sorting portal rows with drag and drop functionality
                    comment_1
                      

                     


                    RickWhitelaw wrote:

                     

                    I assume "trigger" is meant to be literally referenced elsewhere as a variable. Otherwise FM wouldn't recognize it, correct?


                    I am not sure what you mean by "literally referenced". The Let() function allows you you define your own variables in the first section. You can name these variables whatever you like: "trigger" is as good name as any. The variables are evaluated whether they are used in the second section or not.


                    • 7. Re: sorting portal rows with drag and drop functionality
                      mrvodka
                        

                      There are two different types of variables being talked about here. There are script variables which are prefaced with $ or $$ and then the variable within the calculation in the context of the Let statement.

                       

                      The Let () statement can be used to set both types. The script variables can persist beyond the confines of the Let () statement.

                      • 8. Re: sorting portal rows with drag and drop functionality
                        RickWhitelaw
                          

                        Thanks once again. That's clear and gives a whole new functionality to my use of Let.

                         

                        Rick. 

                        • 9. Re: sorting portal rows with drag and drop functionality
                          Steve Wright
                            

                          To : johnhorner

                           

                          Did you read the white paper / PDF file associated with this technique ? 

                          All the answers and explanations are in there... for example :

                           

                          1.  The first line, _trigger = handle, ensures that the calculation will run any time handle is modified. 

                           

                          If you got the demo file from anywhere but excelisys, I recommend searching google for excelisys drag-and-dop should be the first result and downloading from there.

                           

                          If you did read it but just didnt understand, I apologise for chiming in... 

                           

                           

                          • 10. Re: sorting portal rows with drag and drop functionality
                            johnhorner
                              

                            thanks sw, that was very thoughtful to post the reference to the white paper.  i actually had downloaded it but was having some trouble understanding even the explanation itself.  party because of the very basic questions i asked initially about what "_trigger" was, for example.  now that i know it is a variable and triggers re-evaluation of the field handle, i understand the purpose of the first line.  however, i still don't understand a few other elements of this technique and this let() function in particular.  for example:

                             

                            1.  i don't understand what the purpose of the second line is.  i don't ever see this variable (_sortdown) referencedanywhere else again.  why do we care if _sortdown is true or false?

                             

                            2.  i also don't understand the purpose of the calculation at the end of the let() function.  the referenced container field (MAIN::gGraphics [6]) is empty as far as i can tell.  why not just put "" in place of this or some other generic value?

                             

                            3.  i don't understand why the field "handle" even needs a value to be applied at all for the technique to work.  for example, wouldn't it function exactly the same if "handle" contained some random text ("abc") for example or the number "1" or a picture of my dog?  or is it arbitrary because the let() function which is necessary requires a calculation of some sort?

                             

                            4.  while i generally understand the other steps in this auto-enter calculation as well as the steps in the sript trigger and what their purpose is and how they provide relevant information, i still don't quite understand how they actually work together to achieve the drag and drop functionality.  for example, once i click in the field "handle", the script begins and as far as i can tell the if statement would always evaluate false because $$sort_id is empty (by default the first time it is everused and then set to empty everytime the script exits.  at this point "handle" hasn't been madified so it doesn't seem that the auto-enter calcualtion will trigger and reevaluate.  unless simply clicking in the field "handle" itself constitutes the requiredaction necessary to re-evaluate the let() function.  i am assuming that this must be the case or nothing would happen?  so then assuming that clicking inthe field triggers both the script and the let() function simultaneously, how do you know which one runs first or what the order of the steps is?

                             

                            5.  finally, assuming that i understand what is going on with regard to my questions above and that i can grasp how it might evaluate the information based on the portal row which you initially click on to activate this process, how is it "tracking"where you have dragged this portal to?  does just hovering over another portal row's "handle" field trigger the "on enter" script and the let() function?  wouldn't you actually have to click inside of another portal row for these things to trigger.

                             

                            i am clearly missig the key concept.... seems like magic!

                             

                            do a lot of people use this in their solutions?.  i would love to use it is mine.  i tried to create the equivalent set of fields, scripts and functions but i haven't got it to work just yet.  alas....

                             

                            hope someone can enlighten me on how this actually works 

                            • 11. Re: sorting portal rows with drag and drop functionality
                              Steve Wright
                                

                              Although I have 'played' with this technique, I have yet to use their example in terms of sorting, I do however use the drag and drop technique for other things.

                               

                              _trigger and _sortdown force things to re-evaluate,   it isnt used anywhere else and to be honest this is a new concept to me also which Im yet to explore deeper, I use drag and drop techniques but dont need to use a method like that to re-evaluate it, perhaps thats down to the data Im using with my technique.

                               

                              The purpose of handle being a container field is that it allows you to drag and drop without having to first select the contents of the field to be dragged.  If it was text, you would have to select all the text contents before dragging..  With a container it is selected straight away, thus easier for drag and drop.

                               

                              It also contains data irrelevant to your solution, in other words, its not going to mess around with your valuable data.  Of course, handle cannot be blank since there would be no content to drag and drop between container fields, however it can be a space " ", or a picture of your dog ;-)  

                              I myself use a space in the container, then over-lay an image this way Im not moving images between containers or storing images which I will not be using.

                               

                              The last part of the handle calc is simply ensuring the contents remain consistant after a drag and drop, after all you are moving the contents of 1 field to another so to speak.  If you dragged the contents out of the container and moved them, without that, then there would be no content to drag a second time... hence it resets itself.

                               

                              The process looks like this :

                               

                              Drag from sort number 1000  to sort number 1001

                               

                              1. Because you are copying contents in to another instance of handle, the auto enter calc in handle the second instance of handle updates the $$sort_id variable to be the destination 1001 and re-sets its own contents to the image to keep it consistant.

                               

                              2. The script parameter passed using onobject enter is the start field 1000, because this is the first field you entered, the one that initially triggered the script to run.

                               

                              Because of the way script triggers activate, the copy initially goes ahead, allowing line 1 above to evaluate, before the script runs.  Then the script will run..

                              Probably easier to think of it along the lines as validation, copy the value then lets validate it..

                               

                              4. Now of course, all relevant data exists to check the sort number field value against the related fields, so the script can work out what value to set the field to.  Because the obobject enter script takes you back to the original portal row, the value change is made in this row.

                               

                               

                              In conclusion, all your really doing is copying the contents of one container to the other container, however this copy fires of events, the order of which gives the desired results.  Evaluate the auto enter calc then run the script.

                               

                              Its quite a complicated little thing to explain.. but I did my best, considering I have not actually used it for more than maybe an hour or so.... My apologies if anything is wrong ...

                               

                              If its not working for you, look closely at the container fields contents, if they are not an image or a space " " then replace the contents of the field, it wont work with a blank container.  Simply clicking in the field should do nothing... likewise hovering wont trigger anything.

                               

                              Hope that helps somewhat...

                              • 12. Re: sorting portal rows with drag and drop functionality
                                johnhorner
                                   hope that helps somewhat...?  are you kidding?  wow... i feel as though i have had a filemaker epiphany!  thank you so much for not only taking the time to read such a long post, but to write an even longer reply!  i noticed that you had replied earlier in the day but only had a chance about an ago (the suspense was killing me!) to actually read it and then implement my newly gained understanding to get it working in my own database.  until you explained it i was completely missing the key concept that this technique is just playing off the built in ability of filemaker to drag and drop the contents of a container field.  and, as you correctly suspected, my container field was empty and that was the reason it wasn't working in my solution.  so not only is it working now, but i actually understand it!  thank you so much!!!  you have no idea how much head scratching and frustration you have saved me not to mention the benefit to my database.  i will think of you kindly every time i drag and drop to sort my portal rows ;-)
                                • 13. Re: sorting portal rows with drag and drop functionality
                                  Steve Wright
                                    

                                  No worries John..  Im just relieved it actually made some sense lol..

                                  Theres a lot more you can do with drag and drop using those techniques, passing id's / keys across portals etc etc

                                  Once you grasp the principles it opens up a whole new world for exploration...

                                   

                                   

                                  • 14. Re: sorting portal rows with drag and drop functionality
                                    eX-Christo
                                      

                                    "I recently came across a demo file that had the ability to sort portal rows using a drag and drop style method.  it relied on a short script (the script is also copied below if needed) which is triggered when you enter the field ("handle") in the portal row and then relied on an auto-enter calculation in the same field ("handle") which was as follows:"

                                     

                                    If anyone is interested in where John came across this demo, that also comes with a white paper, it is here: http://excelisys.com/web/downloads/index.php

                                     

                                    Please help yourself to any of the other free demos, tips, and tricks files listed as well! Enjoy! 

                                    1 2 Previous Next