Refactor onSort handler and event binding, should support a wider variety of templates