Search code examples
jqueryhtmlsortingtablesorter

How to sort one column depend on the value of another : jquery tablesorter


I am using the tablesorter from motti for sorting the html table.I am unable to find way to sort a certain column depend on another column value. In my case ,wanna sort the FULLNAME column depend on the LASTNAME column value which is basically hidden.Is this possible ? Thanks :-)

  <table id="tblDetails">
<thead>
    <tr>
        <th>FULL NAME</th>
        <th style="display:none;">LAST NAME</th>
        <th>GENDER</th>
        <th>ADDRESS</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>James</td>
        <td style="display:none;">Peter</td>
        <td>male</td>
        <td>washington dc</td>
    </tr>
    <tr>
        <td>jennifer</td>
        <td style="display:none;">lopez</td>
        <td>female</td>
        <td>New york</td>
    </tr>
    <tr>
        <td>Harrison</td>
        <td style="display:none;">Ford</td>
        <td>male</td>
        <td>washington dc</td>
    </tr>
</tbody>


Solution

  • Simple solution would be just adding a hidden span or label before the column (FULLNAME).It will sort depend on the first added value

          <table id="tblDetails">
        <thead>
            <tr>
                <th>FULL NAME</th>
                <th>GENDER</th>
                <th>ADDRESS</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><span style="display:none;">Peter</span>James</td>
                <td>male</td>
                <td>washington dc</td>
            </tr>
       <tr>
            <td><span style="display:none;">lopez</span>jennifer</td>
            <td>female</td>
            <td>New york</td>
        </tr>
        </tbody>
        </table>