1

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

5
  • 2
    (this is a joke) Try Stacksort :-) gkoberger.github.com/stacksort Commented Mar 19, 2013 at 14:24
  • use: tablesorter.com/docs Commented Mar 19, 2013 at 14:32
  • you can also use github.com/ozzyogkush/jquery.sortableTable Commented Mar 19, 2013 at 14:33
  • why do you need jquery to sort on client side while you can sort your things at server side in php Commented Mar 19, 2013 at 14:34
  • sometimes the user may want to sort the data based on other fields or displayed information, and its easier and quicker to just sort it on the page than send requests to the server and have to wait for a response. less resource intensive. Commented Mar 19, 2013 at 16:34

2 Answers 2

1

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(); 
    } 
); 
Sign up to request clarification or add additional context in comments.

Comments

0

you can also use my sortableTable plugin at https://github.com/ozzyogkush/jquery.sortableTable . It's pretty easy to use, and very extensible.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.