jquery tablesorter usage without tbody and th block

I am very much interested to know how to use jquery tablesorter without tbody and th block, the reason behind this is I have many tables and css working which I generated from http://www.csstablegenerator.com/ site, in which only tr and td blocks only used

This is working table with tbody block Working default table style fiddle

But I want to sort table with only tr and td blocks Expected Fiddle

This is my test table which I want to sort

   <table border='1' id='test' >

    <!-- this is my header -->   
           <tr>
               <td>AlphaNumeric</td>
               <td>Numeric</td>
               <td>Animals</td>
               <td>Sites</td>
           </tr>


           <tr>
               <td>abc 123</td>
               <td>10</td>
               <td>Koala</td>
               <td>http://www.google.com</td>
           </tr>
           <tr>
               <td>abc 1</td>
               <td>234</td>
               <td>Ox</td>
               <td>http://www.yahoo.com</td>
           </tr>
           <tr>
               <td>abc 9</td>
               <td>10</td>
               <td>Girafee</td>
               <td>http://www.facebook.com</td>
           </tr>
           <tr>
               <td>zyx 24</td>
               <td>767</td>
               <td>Bison</td>
               <td>http://www.whitehouse.gov/</td>
           </tr>

   </table>

Answers


Assuming you don't want to manually deal with the HTML of the table, so I would get jquery to do it for you:

var header = $("#test tr:first").html();
$("#test tr:first").remove();
$("#test").prepend('<thead>' + header + '</thead>');
$('#test').tablesorter();

Need Your Help

Centralize session management to other Springboot applications

java session spring-boot spring-session session-management

I have some applications with Spring Boot, Spring Security, Spring Sessions and Spring Redis.

make conditionally including other makefiles

bash include makefile conditional

I want to conditionally include makefiles depending on the contents of a xml file and product.