Sort by key for the elements.