Prepare a charcoal or gas grill for medium-high heat, or preheat the broiler.
Place the corn on the grill or in a broiler pan. Cook, turning every 5 minutes, until lightly browned all over, about 20 minutes. Let cool, then cut the kernels from the ears (you should have about 3 cups).
Coat the grill or broiler pan with cooking spray. Grill the onion slices for 5 minutes on each side.
Combine the corn, onions, cilantro, tomatoes, vinegar, salt, pepper and red pepper flakes in a large bowl. Toss well and serve.