6 Replies Latest reply on Apr 15, 2008 11:40 PM by UdoGre

    Sorting property lists

    Level 7
      Okay, I know that you can use the sort() function to automatically sort a
      property list - damn handy at that. The trick is, this function sorts the
      list in order of the properties. So i fI want a list of records sorted by
      Name, then Date, then Amount, I simply have to make sure that the properties
      for each record are declared in that order. Here's the kicker: Say I want
      the user to be able to change the sort-order on the fly. Give them buttons
      to change it to sorting by Date first or Amount first. Or make it possible
      to have the list sort in reverse order. Are there any easy ways of doing
      that? (Short of going through each record and rebuilding them from scratch
      in a different order each time - that would probably work, but it'd be slow
      as dirt on a large data set.) This sort of feature is built into the OS
      (both Win and Mac), and even a feature used in Director's own Cast window in
      List mode, so one would think it'd be available to scripters, but I can't
      seem to find a way to do it.


        • 1. Re: Sorting property lists
          Level 7
          You have to rebuild your propList every time sort criteria are altered
          • 2. Re: Sorting property lists
            Level 7
            > You have to rebuild your propList every time sort criteria are altered

            Ouch, I was afraid of that. Well, maybe they don't need that feature. The
            amount of time it would take to rebuild the propList every time they changed
            their sort criteria just makes it completely non-feasable unless I wanted to
            have a "Sorting... please wait" thing come up when they did it, which just
            sucks, because it's the sort of thing you don't expect to take very long.
            Only other option I can think of is to have several separate copies of the
            propList at once with the params in different order, and switch between them
            based on the user's choice, but now we're talking about lots of redundancy
            and memory wastage (there's alot more than just 3 params in the actual
            data.) I think I'll just drop this idea for now then. Unless there's some
            super-snazzy (and not super-expensive) Xtra out there that does this sort of
            thing more easily...


            • 3. Re: Sorting property lists
              Level 7
              You could always throw your data in a DB and select it using an "order
              by" clause. SQLite and Valentin's xtra are a free option:
              http://dasdeck.de/staff/valentin/xtras/sqlite/
              • 4. Re: Sorting property lists
                stephen_ Level 1
                What do you do with it once it's sorted? Can you just display the data in the sorted order but leave it as is in the list?

                • 5. Re: Sorting property lists
                  Level 7
                  > What do you do with it once it's sorted? Can you just display the data in
                  > the sorted order but leave it as is in the list?

                  Yes, as a matter of fact, the original list must remain unsorted. (Entries
                  must stay in the order they're added for cross-referencing purposes.) What
                  I've been doing is copying the master-list to a new list for
                  sort-and-display purposes. The display list also has a variety of filtering
                  options to only display some of the master-list items by type. But my
                  method for generating the display list copies entire records as a whole,
                  rather than building each record item by item, so I have little say over
                  which order the properties end up in. (Copying the records item by item
                  takes about 5 times as long, processor-wise, I've found. While there's a
                  slight delay when generating and sorting the filtered lists, it's still
                  within the acceptable range. The delay caused by trying to do them item by
                  item is far too long to be acceptable. I'm not sure if interfacing with a
                  database would be better or not, but it sounds like that's just getting
                  overly complex for this purpose. I may have to look into DB management for
                  other reasons, though, so it's not out of the question. I'm just surprised
                  that there isn't an option within the program to do something like this,
                  like:

                  propList.sort(#name)

                  That would be a really elegant way to handle it - if only, if only... Oh
                  well.


                  • 6. Re: Sorting property lists
                    UdoGre
                    Hi Darrel,

                    One other option might be to create several property lists that reference to your master list, one for every property in your master list. Depending on the size of your list, it might be fast enough. DB sound good too, though.

                    Udo