I'm not sure whether your actual question has been answered fully.

The quote you showed appears to be just a book's solution to a problem you didn't show; you also haven't shown what was taught, or what sort of alternative you have in mind. what sort of "grouping" are you asking about?

If the grouping you mean refers to the parenthesized sums in the example, those don't matter at all; just distribute. If you mean what's multiplied (e.g. x by cosine, and not sine by cosine), that is based on thinking about how derivatives work.

The basic idea is that, in order to be able to get some particular function (say, [imath]x\sin(x)[/imath]) by differentiating, we look for what functions yield that sort of term in their derivatives. You can get a power from a higher power, and a sine or cosine from either a sine or a cosine; and you can get a product of functions from a product of functions (by the product rule, which will lead to a sum of terms with different combinations). Experience leads to certain standard "guesses".

Does the text you're learning from have both a list of standard guesses, and some sort of explanation for why they make sense? Here is one that does (much of the explanation is in the solutions):