Please add below script in the footer of the grid question. In "grid_row1", change row number before which you want to add the subheader. Then give the colspan and change it to 1+number of columns.
Using above script, the text "ABC" will appear as a header before row 1 if the question has 5 columns. And the text "PQR" will appear as a header before row 3 if the question has 5 columns.
I hope this helps.