Home > Web Front-end > JS Tutorial > body text

Detailed explanation of how jquery plug-in tablesorter implements html table usage examples

伊谢尔伦
Release: 2017-07-22 09:56:50
Original
2600 people have browsed it

tablesort is a very useful jQuery table sorting plug-in. It supports sorting of multiple data types and will automatically identify the data type of table content, making it very convenient to use.

Use jQuery tablesort to implement the html table method:

1. Download jQuery and tablesort scripts, and reference the script file in html:


<script type="text/javascript" src="../jquery-latest.js"></script>
<script type="text/javascript" src="../jquery.tablesorter.js"></script>
Copy after login

2. Format the html table that needs to be sorted:

a. Specify the CCS class for the table that needs to be sorted: class="sort-table"
b. Use thead and tbody tags to mark the table header and table body
c. In the table header thead, you need to use the th tag to define the table header
The formatted html table is as follows:


<table border=1 width="800px" class="sort-table">
<thead>
 <tr>
 <th>Date</th>
 <th>Usage</th>
 <th>Cost</th>
 <th>Remain</th>
 </tr>
</thead>
<tbody>
 <tr>
 <td>2008-3-25</td>
 <td>book place @dhgu</td>
 <td>-40</td>
 <td>-40</td>
 </tr>
 <tr>
 <td>2008-4-1</td>
 <td>book place @dhgu</td>
 <td>-40</td>
 <td>-80</td>
 </tr>
</tbody>
</table>
Copy after login

3. Add jQuery code to enable html table sorting:
Call the tablesorter() function in the body on the sorted table css class specified in the second step:


<body>
<script type="text/javascript">
 $(document).ready(function() {
 $(".sort-table").tablesorter(); 
 });
</script>
Copy after login

Through the above 3 steps, jQuery tablesort can sort html tables.

The above is the detailed content of Detailed explanation of how jquery plug-in tablesorter implements html table usage examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template