Refactor table creation in preparation for implementing sorting.

Replace row-based onclick with table based onclick.