Skip to content

Instantly share code, notes, and snippets.

@rrickgauer
Last active June 25, 2020 18:55
Show Gist options
  • Save rrickgauer/39fed29080d4d36f7ff1b29c4d780eb8 to your computer and use it in GitHub Desktop.
Save rrickgauer/39fed29080d4d36f7ff1b29c4d780eb8 to your computer and use it in GitHub Desktop.
TableSort.js Example
<!DOCTYPE html>
<html>
<head>
<title>index</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1 class="text-center mt-5">Index</h1>
<table class="table table-bordered table-hover table-condensed" id="table">
<thead>
<tr>
<th data-sort-method="number">id</th>
<th>first_name</th>
<th>last_name</th>
<th>email</th>
<th data-sort-method="date">date</th>
<th data-sort-method="number">amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Lionello</td>
<td>Cavanagh</td>
<td>lcavanagh0@theglobeandmail.com</td>
<td>1/29/2020</td>
<td>176.18</td>
</tr>
<tr>
<td>2</td>
<td>Emmi</td>
<td>Gill</td>
<td>egill1@yellowbook.com</td>
<td>4/23/2020</td>
<td>192.69</td>
</tr>
<tr>
<td>3</td>
<td>Heath</td>
<td>Surmeyer</td>
<td>hsurmeyer2@samsung.com</td>
<td>8/18/2019</td>
<td>241.93</td>
</tr>
<tr>
<td>4</td>
<td>Gannie</td>
<td>Taks</td>
<td>gtaks3@marriott.com</td>
<td>12/22/2019</td>
<td>175.4</td>
</tr>
<tr>
<td>5</td>
<td>Hallie</td>
<td>Ravel</td>
<td>hravel4@dion.ne.jp</td>
<td>10/9/2019</td>
<td>96.06</td>
</tr>
<tr>
<td>6</td>
<td>Consalve</td>
<td>Leroux</td>
<td>cleroux5@narod.ru</td>
<td>8/30/2019</td>
<td>132.08</td>
</tr>
<tr>
<td>7</td>
<td>Hew</td>
<td>Willoughley</td>
<td>hwilloughley6@tiny.cc</td>
<td>10/30/2019</td>
<td>97.83</td>
</tr>
<tr>
<td>8</td>
<td>Donna</td>
<td>Winward</td>
<td>dwinward7@devhub.com</td>
<td>5/10/2020</td>
<td>120.69</td>
</tr>
<tr>
<td>9</td>
<td>Asa</td>
<td>Penson</td>
<td>apenson8@blog.com</td>
<td>11/19/2019</td>
<td>184.21</td>
</tr>
<tr>
<td>10</td>
<td>Kalila</td>
<td>Lohan</td>
<td>klohan9@arstechnica.com</td>
<td>10/23/2019</td>
<td>232.39</td>
</tr>
<tr>
<td>11</td>
<td>Kayle</td>
<td>Fairbeard</td>
<td>kfairbearda@sitemeter.com</td>
<td>11/29/2019</td>
<td>170.97</td>
</tr>
<tr>
<td>12</td>
<td>Imojean</td>
<td>Hrinishin</td>
<td>ihrinishinb@jugem.jp</td>
<td>10/11/2019</td>
<td>122.69</td>
</tr>
<tr>
<td>13</td>
<td>Ardella</td>
<td>McAmish</td>
<td>amcamishc@fda.gov</td>
<td>11/2/2019</td>
<td>115.25</td>
</tr>
<tr>
<td>14</td>
<td>Lydia</td>
<td>Maccrae</td>
<td>lmaccraed@163.com</td>
<td>10/11/2019</td>
<td>51.92</td>
</tr>
</tbody>
</table>
</div>
<!-- bootstrap js -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<!-- core -->
<script type="text/javascript" src="tablesort/tablesort.min.js"></script>
<!-- additional libraries -->
<script type="text/javascript" src="tablesort/tablesort.date.min.js"></script>
<script type="text/javascript" src="tablesort/tablesort.number.min.js"></script>
<!-- create table sort variable -->
<script type="text/javascript">
new Tablesort(document.getElementById('table'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment