Sort fixes

 - Emit templateSet when the template was set.
 - Use call() function to call the functions.
 - Fixes in sort.js file.