Home  >  Q&A  >  body text

HTML table sorting

<p>So basically I'm running a mysql query that fetches data from my database and displays it in an easy-to-read layout for the user. </p> <pre class="brush:php;toolbar:false;">Name-----Address----Sales Person</pre> <p>You get the gist. Now I want the user to sort the html table by salesperson. How can I easily do this using a dropdown menu? </p> <p><br /></p> <pre class="snippet-code-html lang-html prettyprint-override"><code><div class='menu'> <ul> <li><a href='#'><span>Sales Person</span></a> <ul> <li><a href='#'><span>Melissa</span></a></li> <li><a href='#'><span>Justin</span></a></li> <li><a href='#'><span>Judy</span></a></li> <li><a href='#'><span>Skipper</span></a></li> <li><a href='#'><span>Alex</span></a></li> </ul> </li> </ul> </div></code></pre> <p><br /></p>
P粉752479467P粉752479467442 days ago520

reply all(2)I'll reply

  • P粉785905797

    P粉7859057972023-08-28 10:42:03

    This is another library.

    The changes that need to be made are -

    1. Add sorting js

    2. Add the class name sortable to the table.

    Click on the table title to sort the table accordingly:

    <script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>
    
    <table class="sortable">
      <tr>
        <th>Name</th>
        <th>Address</th>
        <th>Sales Person</th>
      </tr>
    
      <tr class="item">
        <td>user:0001</td>
        <td>UK</td>
        <td>Melissa</td>
      </tr>
      <tr class="item">
        <td>user:0002</td>
        <td>France</td>
        <td>Justin</td>
      </tr>
      <tr class="item">
        <td>user:0003</td>
        <td>San Francisco</td>
        <td>Judy</td>
      </tr>
      <tr class="item">
        <td>user:0004</td>
        <td>Canada</td>
        <td>Skipper</td>
      </tr>
      <tr class="item">
        <td>user:0005</td>
        <td>Christchurch</td>
        <td>Alex</td>
      </tr>
    
    </table>

    reply
    0
  • P粉642920522

    P粉6429205222023-08-28 00:27:23

    Check if you can use any of the JQuery plugins mentioned below. Simply fantastic, offers a wide range of working options and is less effort to integrate. :)

    https://github.com/paulopmx/Flexigrid - Flexgrid
    http://datatables.net/index - Data table.
    https://github.com/tonytomov/jqGrid

    If not, you need to have a link to the headers that call the server-side script to invoke the sort.

    reply
    0
  • Cancelreply