I see two options and do both, depending on the case.
1. Try to change their attitude. I know it's not easy and could be a total waste of time. Sometimes negative people are looking for attention. Those who are constantly complaining, might be looking for emphaty. I can understand that but this however can be very tiering and energy consuming for others. Maybe if you can make them understand that this is bad for both parties, you can change them. But they have to see the benefits of being positive.
2. Avoid and ignore them. Ignorance hurts the most. This can be a wake up call for them. Some might realize what they are loosing, others might get stubborn and continue to be negative because winning feels great and they can't give up. In this case I usually walk away and cut them out of my like if i can.
Positivity will always win over negativity, I'm pretty confident about that. Positivity has way more benefits than negativity.
Positive people will always be popular and gather a lot of people around them. Negative people will not.
Everyone deserves to be helped but I'm not going to waste my time on negative people, especially when I see they enjoy being negative and have no intention of changing. We only live once and life is short.
Simolemente stop talking to that kind of people (Only if it really bothers you).
There are relatives and even our father, or partner who are usually very grumpy and negative. With whom we could do an exepcioon and support their negativity.
On the other hand, if it is a person that I do not know much about, just to get away, most people do not change.
Success as well as negativity are a snowball.
The more you push the more it grows.
The idea is to stop it from root.
Just recently, I encountered someone with a negative attitude, with my knowledge and some sort of digital evolution - I try to understand his/her thoughts about its negativity.
To deal with them, you first need to approve what he/she thinks about it, but also state your stand on why not this - you can never say always YES to people with negative reactions, they needed a little bit of understanding, Don't be positive instead stay being realistic or idealistic, give them ideas that respects with nature itself.
Try to support his idea or his/her negativity but always suggest a better one, in a simple way. They just needed help and that is all in my own opinion.