Andre Simmons
Andre Simmons

Reputation: 13

How to reorder table rows using Jquery or Javascript

I have a table similar to the following:

Level
$1,000
$500
$100
Other Amount

The HTML is generated by a web based program that allows you to enter your desired values but does not provide an option to re-order them.

The values are ordered highest to lowest but I need them to be lowest to highest.

Here is the HTML that produced the table:

<table width="100%" id="TablePledgeLevelInner">
<tbody>
    <tr>
        <td width="1%">&nbsp;</td>
        <td>Level<br>
        </td>
    </tr>
    <tr>
        <td nowrap="">&nbsp;
            <input type="radio" id="Radio1" onclick="SetAmount(form, 1000);" value="764853" name="PledgeLevelID">&nbsp;
        </td>
        <td>$1,000&nbsp;<br>
        </td>
    </tr>
    <tr>
        <td nowrap="">&nbsp;
            <input type="radio" id="Radio1" onclick="SetAmount(form, 500);" value="764915" name="PledgeLevelID">&nbsp;
        </td>
        <td>$500&nbsp;<br>
        </td>
    </tr>
    <tr>
        <td nowrap="">&nbsp;
            <input type="radio" id="Radio1" onclick="SetAmount(form, 100);" value="764921" name="PledgeLevelID">&nbsp;
        </td>
        <td>$100&nbsp;<br>
        </td>
    </tr>
    <tr>
        <td nowrap="">&nbsp;
            <input type="radio" id="Radio1" onclick="SetAmount(form, 0);" value="764922" name="PledgeLevelID">&nbsp;
        </td>
        <td>Other Amount&nbsp;<br>
        </td>
    </tr>
</tbody>
</table>

How would I reorder this table using Jquery or Javascript? Thanks in advance. Any help is greatly appreciated.

Upvotes: 1

Views: 2957

Answers (1)

jameslafferty
jameslafferty

Reputation: 2182

Use jQuery DataTables. It'll let you sort the output and provide loads of other nice functionality out of the box.

Upvotes: 4

Related Questions