• Hi Everyone,

    Looking for some helpful pointers if anyone knows

    I have a product table on my website which is built from SQL queries. I’d like to add sorting functions to the top headers, and found this java script option at http://tablesorter.com/docs

    I think Ive followed the instructions correctly, but cant seem to get it to work. Ive added the js files to folder under “wp-content/scripts”.

    Ive entered the following code in to the header file (note I have also tried adding this directly to the template php file as well)

    <script type="text/javascript" src="/wp-content/scripts/jquery-latest.js"></script>
    <script type="text/javascript" src="/wp-content/scripts/jquery.tablesorter.js">
    
    $(document).ready(function()
        {
            $("#myTable").tablesorter();
        }
    ); 
    
    </script>

    I then have the following code that builds my table

    <?php
    global $wpdb;
    $products = $wpdb->get_results("SELECT * FROM products WHERE type='ax' AND vtype='ACT' ");
    
    echo "<table id='mytable' class='tablesorter'>";
    echo "<thread>";
    echo "<th>Part Image</th>";
    echo "<th>Part Number</th>";
    echo "<th>Size</th>";
    echo "<th>Dep</th>";
    echo "<th>Vol</th>";
    echo "<th>Curr</th>";
    echo "<th>Power</th>";
    echo "<th>Air</th>";
    echo "<th>Pres</th>";
    echo "</thread>";
    
    foreach($products as $part_num){
    echo "<tbody>";
    echo "<tr>";
    echo "<td><img src=".$part_num->image.\"></td>";
    echo "<td>".$part_num->part_num."</td>";
    echo "<td>".$part_num->size."</td>";
    echo "<td>".$part_num->dep."</td>";
    echo "<td>".$part_num->vol."</td>";
    echo "<td>".$part_num->curr."</td>";
    echo "<td>".$part_num->power."</td>";
    echo "<td>".$part_num->air."</td>";
    echo "<td>".$part_num->pres."</td>";
    echo "</tr>";
    echo "<tbody>";
    }
    echo "</table>";
    ?>

    Any help would be gratefully appriciated

    Thank you

The topic ‘Table Sorter javascript’ is closed to new replies.