Order doesn't match when sorting 2 elements by same keys

I encounter this issue a lot.
When sorting 2 lists that don’t come from the same source:

  • Contain different elements eg. schedules and phases
  • Contain same elements but from different sources eg. shedules from “all elements of category” and “currently sellected”
    Or any other different source.
    In those cases when sorting 2 lists by same keys the order doesn’t match:

    In this case I just used sortByFunction (functione: element.name) but in some cases that’s not an option and I just want to sort by key like substring and both lists sort in different ways.

Any idea how to keep them sorting in the same order when for example sorting 2 lists by name substring?

Make a dictionary as they come naturally with the list you can sort as the keys, sort the keys list as you please, then recal the second list in the desired order by getting value at key using the sorted list as the key.

This will work if you dont have multiple instances of the same under the keys category.

1 Like