Please see my comment to the question. My advice cannot be a final answer as I never did it, just the idea.
I would take a source code of something like a table sorter,
http://tablesorter.com/docs/#Download[
^] to see how it works. It could be relatively complex but comprehensible, I hope.
It may not work across a set of different
tbody
elements (check it up though), but you could 1) evaluate performance for the volumes of data your applications require; 2) if it cannot work this way, understand how it works and write a modified component implementing this feature. The idea should be pretty much the same.
[EDIT]
This is why I think that the library modification should be not too hard:
The element
<tbody>
is not a huge barrier, and this is because table is arranged in a DOM tree by rows, not by columns.
[END EDIT]
Sorry if you find it too difficult to achieve, but this is the only way I personally can think of at the moment. Maybe you could find something else closer to your needs.
—SA