It might be easier to think of 掛けに as an old-fashioned 途中で as they are almost always interchangeable. Now, what differs between 途中で and ついでに is the order in which actions are performed. Let’s look at some examples to see how they are both interpreted:
「コンビニに行ったついでに本屋に寄った。」
This sentence can either mean “I went to the convenience store and the bookstore” or “I went to the bookstore and the convenience store.” This is why ついでに is often interpreted as “while you’re at it” with no clear way to tell which action was performed first (it is irrelevant).
「コンビニに行く途中で本屋に寄った。」
This sentence can only mean “I stopped by the bookstore on the way to the convenience store.” The speaker is expressing that they went to the bookstore first and then went to the convenience store. This is why the kanji in 掛けに (掛) can be interpreted as “in the midst of.”
I hope this helps! Cheers.