6 Replies Latest reply on Jan 4, 2016 11:43 AM by siplus

    Don't keep Portal Sorted !

    petery009

      Hi Everyone

       

      Is there a way to sort the portal whenever you want by click a button? And really the question is don't keep the portal always sorted.

      For example: in the portal, i have a field ID,

      ID

      5

      4

      I click the button to sort. now the portal should looks like:

      ID

      4

      5

      I add a new record, ID: 3, i want the portal looks like:

      ID

      4

      5

      3

      NOT Like:

      ID

      3

      4

      5

       

      Hope the question makes sense.

       

      Thanks.

      --Peter

        • 1. Re: Don't keep Portal Sorted !
          mikebeargie

          Portal sorting is based on a field, so what you need is a field in your portal table that will calculate the correct sort value for you.

           

          So in essence when your data is:

          ID

          4

          5

          3

          Your sort key field contains:

          ID

          1

          2

          3

          To accomplish this in your use case, I would use a script that replaces the related records sort key with a value, and then have that field contain an auto-enter calc that enters the next highest value (EG if the highest sort order is 3, enter 4).

           

          1) Create the field in your portal table: portalTable::sortKey - type numeric. Set it with an auto-enter calculation of:

          ExecuteSQL("SELECT MAX(sortKey) FROM portalTable";"";"") + 1

          This will auto-enter the next highest number in order. Doesn't matter if you have sort orders specified for other records as well.

           

          2) Set your portal to sort records by portalTable::sortKey ascending.

           

          3) Create a script that refreshes the sort values on demand:

          Freeze Window

          Go To Related Records [ from portalTable, matching current record, using any portalTable layout]

          Sort Records [ portalTable::ID ascending ]

          Replace Field Contents [ portalTable::sortKey ; serial numbers starting with 1, incrementing by 1]

          Go To Layout [ your main screen ]

          Refresh Window [ flush cached content ]

           

          That's it!

          • 2. Re: Don't keep Portal Sorted !
            petery009

            Hi Mike

             

            That's very helpful. Thanks a lot. I kind of know this way but yours is way better than what i thought in my mind. Anyway, i would like to find a way to do this by not specify a field in the portal. just simply by sort by field script for example. (Maybe it does not work.)

            Please someone confirm that for me, so i just have to use this way then.

             

            The reason i was a bit "picky" here is i am changing this on an existing file.(ideally i want to do very minimum changes and make sure very minimum impact on exist system)

             

            Thanks.

            --Peter

            • 3. Re: Don't keep Portal Sorted !
              mikebeargie

              Portals are sorted either by the relationship from the parent to the portal table, or by the checkbox under the portal settings dialog.

               

              Thus a field IS required to sort a portal. What field you specify is up to you, and you can certainly customize the field contents like I have shown you.

               

              However, there is no "sort portal" script step that will magically override the portal settings you have established, those are coded to the layout.

               

              There is a more complex option that allows you to specify the sort order with a value list, but it's much more difficult to explain and not any better to use in your case.

              • 4. Re: Don't keep Portal Sorted !
                siplus

                IMHO the best answer to your question needs to know how many records are behind that portal (and how many you think you'll have in a year from now). How many users also counts.

                 

                For example, one "think different" idea could be to have 2 relationships, a sorted one and a normal one. 2 portals, one over the other, and a "hide when" which decides which one is being displayed.

                • 5. Re: Don't keep Portal Sorted !
                  mikebeargie

                  the method I described handles multiple users as well. There is the potential that it could slow down under a ton of related records in the portal, but at that point you could switch to "perform script on server" to speed it back up again.

                  • 6. Re: Don't keep Portal Sorted !
                    siplus

                    Replace field contents is not so multi user friendly in my book.