Table sorting function should be implemented in the project.
There are many solutions online, many of which are based on jQuery.
, 17KB in size, but its home page has some compatibility problems under ie10.
DataTables, size 75KB, powerful, with paging, search and other functions.
There is also a plug-in called sortElements, which is very small, only 3KB, and has good compatibility, and has 818 stars on Github.
Finally, I chose to use sortElements, and the implementation is very simple:
1. Introduce jQuery
<script type="text/javascript" src=""></script>
2. Introduce
<script type="text/javascript" src=""></script>
3. js code
$(document).ready(function(){
var table = $('#mytable');//table's id
$('#sort_header')//Headerid to sort
.each(function(){
var th = $(this),
thIndex = (),
inverse = false;
(function(){
('td').filter(function(){
return $(this).index() === thIndex;
}).sortElements(function(a, b){
return $.text([a]) > $.text([b]) ?
inverse ? -1 : 1
: inverse ? 1 : -1;
}, function(){
return ;
});
inverse = !inverse;
});
});
});
4. html code
<table >
<tr>
<th >Facility name</th>
<th>Phone #</th>
<th >City</th>
<th>Speciality</th>
</tr>
<tr>
<td>CCC</td>
<td>00001111</td>
<td>Amsterdam</td>
<td>GGG</td>
</tr>
...
</table>
There are many solutions online, many of which are based on jQuery.
, 17KB in size, but its home page has some compatibility problems under ie10.
DataTables, size 75KB, powerful, with paging, search and other functions.
There is also a plug-in called sortElements, which is very small, only 3KB, and has good compatibility, and has 818 stars on Github.
Finally, I chose to use sortElements, and the implementation is very simple:
1. Introduce jQuery
Copy the codeThe code is as follows:
<script type="text/javascript" src=""></script>
2. Introduce
Copy the codeThe code is as follows:
<script type="text/javascript" src=""></script>
3. js code
Copy the codeThe code is as follows:
$(document).ready(function(){
var table = $('#mytable');//table's id
$('#sort_header')//Headerid to sort
.each(function(){
var th = $(this),
thIndex = (),
inverse = false;
(function(){
('td').filter(function(){
return $(this).index() === thIndex;
}).sortElements(function(a, b){
return $.text([a]) > $.text([b]) ?
inverse ? -1 : 1
: inverse ? 1 : -1;
}, function(){
return ;
});
inverse = !inverse;
});
});
});
4. html code
Copy the codeThe code is as follows:
<table >
<tr>
<th >Facility name</th>
<th>Phone #</th>
<th >City</th>
<th>Speciality</th>
</tr>
<tr>
<td>CCC</td>
<td>00001111</td>
<td>Amsterdam</td>
<td>GGG</td>
</tr>
...
</table>