Separating table and filter templates for much agile UI

It's working, but probably global var 'spaces' is not very suitable.
Don't know elegant way to implement such a function.