Lightweight jQuery Plugin For Sortable Tables - Sortable.js

Lightweight jQuery Plugin For Sortable Tables - Sortable.js
File Size: 4.32 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Sortable.js is a lightweight jQuery script to sort a table column in alphabetical order by clicking the header.

How to use it:

1. Load the jQuery javascript library and jQuery sortable.js in the html document.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="src/jquery.sortable.js"></script>

2. Create a sortable html table following the markup structure like this:

<table class="sortable">
<thead data-header="true">
<tr>
<th data-sort-column="true">ID</th>
<th data-sort-column="true">Name</th>
<th data-sort-column="true">Last Name</th>
<th data-sort-column="true">Birthday</th>
<th data-sort-column="true">Note</th>
</tr>
</thead>
<tbody data-body="true">
<tr>
<td>1</td>
<td>John</td>
<td>Doe</td>
<td data-sort-value="1987-12-08">December 8, 1987</td>
<td>Morbi id felis metus</td>
</tr>
<tr>
<td>2</td>
<td>Jane</td>
<td>Pope</td>
<td data-sort-value="1975-10-14">October 14, 1975</td>
<td>Maecenas id enim vel lectus lobortis molestie</td>
</tr>
<tr>
<td>3</td>
<td>Bob</td>
<td>Ludwig</td>
<td data-sort-value="1995-05-05">May 5, 1995</td>
<td>Cras mi purus, dapibus in ipsum a, malesuada facilisis dolor</td>
</tr>
<tr>
<td>4</td>
<td>Anne</td>
<td>Heisenberg</td>
<td data-sort-value="1967-01-31">January 31, 1967</td>
<td>Aliquam egestas tincidunt purus, a sagittis neque lacinia vehicula</td>
</tr>
<tr>
<td>5</td>
<td>Kate</td>
<td>Miller</td>
<td data-sort-value="1991-08-17">August 17, 1991</td>
<td>Pellentesque vitae nulla elit</td>
</tr>
</tbody>
</table>

3. Initialize the plugin by calling the sortable() function on your table.

<script>
$(function() {
$('.sortable').sortable();
});
</script>

This awesome jQuery plugin is developed by miriti. For more Advanced Usages, please check the demo page or visit the official website.