Click here to Skip to main content
16,021,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Say there are 3 TBODY tags inside one single table containing 3,4 and 5 number of columns.
Is it possible for all the TBODIES to get sorted if any column header on say TBODY1 is clicked.
I want the whole table to get sorted , not just the columns in one particuular TBODY.
I had some reason for which I had to use multiple TBODY's inside one single table. Can anyone guide me on this ?

Thanks
Posted
Comments
RDBurmon 15-Feb-12 9:54am    
Can you post your table structure and restate your question by using some name from image ?
Sergey Alexandrovich Kryukov 16-Feb-12 1:21am    
Sound pretty tricky...
If is of course quite possible as you can always manipulate element's innerHTML, but how effective can it be... hard to say. Anyway, what have you tried?

Is the table big, by the way? If it's 10x10 or something, it's not a big deal, but if it's really big, I would concern about performance...
--SA
Warreer 16-Feb-12 1:32am    
I have used this javascript library: kryogenix.org/code/browser/sorttable But I guess it works only for a table with single tbody.Is there any other way out to accomplish this task? Table is not big.
Sergey Alexandrovich Kryukov 16-Feb-12 1:35am    
Yes, if it is not too big, this is quite doable, but how much work? Please see my answer; try another library or something else. My idea is that you can modify it. You see, tbody is not a huge barrier, and I can tell you why: because table is arranged in a DOM tree by rows, not by columns. By this reason, I don't think "jumping" over the tbody tag could be too hard...
--SA
Warreer 16-Feb-12 1:39am    
Yeah, right.I think I should start looking into the library that I used or the one you suggested and make it work according to my need.Thank you !

I have modified the sorttable.js library (version 2) to accomplish my task of sorting multiple tables that are separated by design but related to each other.I have applied the sorting for the first table and other two tables get sorted accordingly.
 
Share this answer
 
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
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900