I recently had a play with this plugin that makes using dataTables easier with Moodle tables
https://moodle.org/plugins/tool_datatables
I tried the suggested example with the ad-hoc queries plugin and it made the columns sortable. Strangley it gave no indication they were sortable, but clicking on the header did the sorting thing very nicely.