Because your sentence has a Non - Restritive clause,(meaning: if the word "table" is left out, will the 2nd clause still make sense?) it should read like this:
There was a hat on the table, which belonged to my grandmother.
another example:
There was a hat which belonged to my grandmother
or
There was a hat that belogned to my grandmother.
Because you have the word table, you must put a comma before which.
---The typo errors in past tense on two meanings:-
eg:-Typo errors on the past tense:grandmother instead of grandfather; -eg:-
There was a hat on the table which belonged to my grandmother.
eg:-There was a hat, which belonged to my grandmother, on the table.