They each have their advantages and disadvantages.
Most donations have no restrictions.* People give to support the mission in general. Most grants have some type of restriction. Foundations tend to fund specific projects. Nonprofits should use donations to fund expense areas that foundations do not fund, such as salaries, and use grant funding to support projects.
Although grants have some restrictions, they can sometimes be less restrictive. As long as the money is used for the program, it can be used for any part of that program including salaries. If a nonprofit does this, they need to make it clear in the application.
The disadvantage of donations is most come in November and December and the amounts are unpredictable. To get donations at other times, nonprofits run a fund-raising campaign, which is usually for a specific project, or hold an event, like a concert, dance, or game night (there are many other examples).
The advantage from foundations is they publish a timeline for approval and issuing funds, along with a range of amounts, if they approve the grant. Also, some foundations provide money at the same time for the same project each year. A nonprofit can make plans and have reasonable assurance of a steady income.
As I noted in a recent blog post, Balancing Act, this is another reason for nonprofits to use equal effort and pursue funding from both donations and grants. I have worked with nonprofits receiving donations and grants and they have more stable funding.
* Note: However, some people donate for a specific program or operations.