Excellent suggestion from Alain Knaff:
Rather than sorting the rows directly on the target column's key ("colval"), sort it instead on the pair [colval, initial_pos], where initial_pos is the position the column had after the previous sort (i.e. if colval compare equal, compare initial_pos to break ties).