[英]Sorting table rows by a column
我在表格中有一个使用地理位置API计算距离的城市列表。 我想按距离列自动对表格行进行排序。 我试过几个表排序插件,但都失败了。
有什么建议吗? 这是我的代码: jsfiddle.net/vLLsLLrb/
表格的外观如下:
为了快速做到这一点,我通过执行以下步骤来使用sorttable.js :
基本上,主要是更改表格标签:
<table id="nearest" class="table table-striped sortable">
<thead>
<tr>
<th>Destination</th>
<th>Distance to</th>
</tr>
</thead>
<tbody>
<tr>
<th>London</th>
<td><span id='london'></span>
</td>
</tr>
<tr>
<th>Newcastle</th>
<td><span id='newcastle'></span>
</td>
</tr>
<tr>
<th>Cardiff</th>
<td><span id='cardiff'></span>
</td>
</tr>
<tr>
<th>Cambridge</th>
<td><span id='cambridge'></span>
</td>
</tr>
<tr>
<th>Reading</th>
<td><span id='reading'></span>
</td>
</tr>
</tbody>
</table>
就是这样,现在您的距离列旁边还有一个排序三角形! 这是jsfiddle!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.