Reputation: 299
I have this table
<table>
<th>
Food Name
</th>
<th>
Restaurant Name
</th>
<?php
if ($isCustomer == "1") {
?>
<th>
</th><?php
}
?>
<?php while ($row = $allFoods->fetch()) { ?>
<tr>
<td>
<?php echo $row['foodName']; ?>
</td>
<td>
<?php echo $row['restaurantName']; ?>
</td>
<?php
if ($isCustomer == "1") {
?>
<td class="favoriteRow">
<a class="link" href="<?php echo URL . 'customer/addFavoriteFood/' . $row['foodID'] ?>"> Add Favorite</a>
</td>
<?php
}
?>
</tr>
<?php } ?>
</table>
I tried to sort it a lot, but i couldn't, it seems like i have to reload the page with the already sorted items, but i need to sort it using jquery, any help will be appreciated
Upvotes: 1
Views: 1151
Reputation: 3844
I succeed with jquery tablesorter, it's very simple way to sort html tables.
code sample as below,
html:
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Email</th>
<th>Due</th>
<th>Web Site</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smith</td>
<td>John</td>
<td>[email protected]</td>
<td>$50.00</td>
<td>http://www.jsmith.com</td>
</tr>
<tr>
<td>Bach</td>
<td>Frank</td>
<td>[email protected]</td>
<td>$50.00</td>
<td>http://www.frank.com</td>
</tr>
<tr>
<td>Doe</td>
<td>Jason</td>
<td>[email protected]</td>
<td>$100.00</td>
<td>http://www.jdoe.com</td>
</tr>
<tr>
<td>Conway</td>
<td>Tim</td>
<td>[email protected]</td>
<td>$50.00</td>
<td>http://www.timconway.com</td>
</tr>
</tbody>
</table>
jquery:
$(document).ready(function()
{
$("#myTable").tablesorter();
}
);
Upvotes: 1
Reputation: 4751
you can also use my sortableTable plugin at https://github.com/ozzyogkush/jquery.sortableTable . It's pretty easy to use, and very extensible.
Upvotes: 0