My Table structure is like below:
This is my HTML:
<table id="jackpotwatch" style="width:700px;">
<thead>
<tr>
<th>Location</th>
<th colspan="2">Full Name</th>
<th>Amount</th>
</tr>
<tr >
<th>Asset</th>
<th>Patron ID</th>
<th>User</th>
<th>Date/Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>Salem</td>
<td colspan="2">Bob galvin</td>
<td>$3400</td>
</tr>
<tr>
<td>assert1</td>
<td>1148</td>
<td>sjauser</td>
<td>11/12 10:39 AM</td>
</tr>
<tr>
<td>chennai</td>
<td colspan="2">sally n safer</td>
<td>$400</td>
</tr>
<tr>
<td>sdfsdgt1</td>
<td>4747</td>
<td>sjauser</td>
<td>11/12 10:39 AM</td>
</tr>
<tr>
<td>Mazdgfdg</td>
<td colspan="2">afdagadg</td>
<td>789769</td>
</tr>
<tr>
<td>qwqeqe</td>
<td>47467</td>
<td>sjauser</td>
<td>11/12 10:39 AM</td>
</tr>
<tr>
<td>hurtyry</td>
<td colspan="2">afadfadg</td>
<td>$12000</td>
</tr>
<tr>
<td>afadsf</td>
<td>25426546</td>
<td>sjauser</td>
<td>11/12 10:39 AM</td>
</tr>
</tbody>
</table>
When i click on the "Amount" header the amount values ($3400, $400, $12000) should be sorted, etc. Like that Date/Time field also should sort based on the value.
I used Tablesorter plugin but that plugin not sorting all columns. It not sorting last column and second row header in this table. I also used Tinysort plugin but it change the table structure itself while sorting.
I cannot able to change the table structure as this is our client biggest requirement. Please provide some guide on this sorting problem which is very useful for me.
Any customized sorting we can apply means please suggest how can i do that.
See the Demo here.
I don't have a plugin for you, but I came up with the following approach for your specific situation:
This makes each
TH
element in theTHEAD
element, sortable. It sorts it based on a textual, lowercased, comparison.It is hard coded to only work with records that are 2 row sets, but could be expanded to allow the configuration of how many rows make up a single record, or even deduce this automagically by counting how many rows are in the
THEAD
.I used this on the following HTML:
Make sure to place the script either after the HTML, or in a ready event handler:
Presumably you want the two rows for each entry to remain grouped together, in which case Tablesorter isn't designed to do what you want. Tinysort could work, though, if you were prepared to put each pair of rows into its own
tbody
:Since Tinysort can apparently sort on any kind of element, you should be able to tell it to sort the
tbody
elements instead of the rows. Your script could do something like this, loosely based on the table example in the Tinysort docs:This relies on there being precisely the same number of cells in the header rows as in the rows of each tbody.