Forums

Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum Sort all lists based on a column of one list

  • Sort all lists based on a column of one list

    Posted by maxperique on March 10, 2026 at 3:33 pm

    Hi.

    I’ve got N lists called ivList[n] for n=1…N. Each list has got EXACTLY the same number of lines but different columns except for the first (that contains EXACTLY the same values for all lists).

    I’d like to sort all N lists at once, based on a specific column of a single chosen list.

    Say, for example, that I’ve got 3 lists (ivList1, ivList2, and ivList3) and I want to sort all lists based on the 2nd column of list ivList1 (ivList1.C2).

    I tried with

    ivList2.$sort(ivList1.C2)

    ivList3.$sort(ivList1.C2)

    but it doesn’t work since (I guess…) the calculation is not a reference to a column of the list that is calling the $sort() method.

    Is there a fast built-in Omnis method/procedure to do this? Maybe using $sendall()…?

    Many thanks.

    maxperique replied 2 days, 17 hours ago 2 Members · 4 Replies
  • 4 Replies
  • Andreas Pfeiffer

    Administrator
    March 10, 2026 at 3:50 pm

    Hi Massimo,

    What do you mean with “based on the 2nd column of ivList1”?

    Do you mean a value from ivList1 and if so, in which line? Is there any current line set?

    Best,

    Andreas

    • maxperique

      Member
      March 10, 2026 at 6:57 pm

      Hi Andreas.

      Something like the attached example.

      ivList1 is sorted based on $ref.C2 and so does ivList2: it is sorted based on ivList1.C2, as if they were a single list…

      • Andreas Pfeiffer

        Administrator
        March 11, 2026 at 8:33 am

        Massimo,

        Do I understand this correctly that you want to sort all lists in that instance the same column in one go?

        Assuming that all those lists are instance variables of the current instance you could do something like this:

        Do $cinst.$ivars.$sendall($ref.$sort($sendallref.c2),$ref.$type=kList)

        So basically you would send a message to all members of the $ivars group in the current instance that are of type list to do a sort on column 2 (c2).

        Does that help?

        Best regards,

        Andreas

        • maxperique

          Member
          March 11, 2026 at 9:23 am

          Hi Andreas.

          This command will sort all lists based on the 2nd column of each list. So the 2nd list in the example would be A,B,C instead of B,C,A

          I’d need instead something like this

          Do $cinst.$ivars.$sendall($ref.$sort(ivList1.C2),$ref.$type=kList)

          The fastest way to do it, that I found so far, is to add ivList1.COL1 to ivList2 (with another column name, e.g. TEMP), do ivList2.$sort($ref.TEMP) and finally remove it ivList2.$cols.$remove(ivList2.$colcount)

          • This reply was modified 2 days, 17 hours ago by  maxperique.

Log in to reply.