在可排序中设置默认的排序列 [英] Set a default sort column in Sortable

查看:60
本文介绍了在可排序中设置默认的排序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Sortable (一个jQuery插件),我想选择一个默认值列,用于对每个负载进行排序.

Using Sortable, a jquery plugin, I would like to choose a default column for sorting on each load.

例如,按类别名称为".column5"的列进行排序

For example, sort by the column which has the class name ".column5"

如何使用可排序的jquery插件执行此操作?

How can I do this using the sortable jquery plugin?

推荐答案

根据文档,您可以在页面加载时执行此操作.

According to the documentation, you can do this on page load.

$(document).ready(function(){
  $("th.sort").each(function(){
    sorttable.innerSortFunction.apply(this, []);
  })
})

th, td {
  padding: 3px
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>


<table class="sortable">
  <thead>
    <tr>
      <th>Name</th>
      <th class="sort">Salary</th>
      <th>Extension</th>
      <th>Start date</th>
      <th>Start date (American)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
        <td>Bloggs, Fred</td>
        <td>$12000.00</td>
        <td>1353</td>
        <td>18/08/2003</td>
        <td>08/18/2003</td>
    </tr>
    <tr>
        <td>Turvey, Kevin</td>
        <td>$191200.00</td>
        <td>2342</td>
        <td>02/05/1979</td>
        <td>05/02/1979</td>
    </tr>
    <tr>
        <td>Mbogo, Arnold</td>
        <td>$32010.12</td>
        <td>2755</td>
        <td>09/08/1998</td>
        <td>08/09/1998</td>
    </tr>
    <tr>
        <td>Shakespeare, Bill</td>
        <td>$122000.00</td>
        <td>3211</td>
        <td>12/11/1961</td>
        <td>11/12/1961</td>
    </tr>
    <tr>
        <td>Shakespeare, Hamnet</td>
        <td>$9000</td>
        <td>9005</td>
        <td>01/01/2002</td>
        <td>01/01/2002</td>
    </tr>
    <tr>
        <td>Fitz, Marvin</td>
        <td>$3300</td>
        <td>5554</td>
        <td>22/05/1995</td>
        <td>05/22/1995</td>
    </tr>
  </tbody>
</table>

<pre><code>
$(document).ready(function(){
  $("th.sort").each(function(){
    sorttable.innerSortFunction.apply(this, []);
  })
})
</code></pre>

该类可以是您想要的任何类,但请确保jQuery调用也已更改.

The class can be anything you would like, but make sure the jQuery call is changed as well.

这篇关于在可排序中设置默认的排序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆