【问题标题】:Auto sort the table using sorttable.js使用 sorttable.js 对表格进行自动排序
【发布时间】:2012-12-14 21:28:50
【问题描述】:

我正在尝试使用此脚本对 html 表进行排序:http://www.kryogenix.org/code/browser/sorttable/

JS 代码本身:http://www.kryogenix.org/code/browser/sorttable/sorttable.js

我使用了customkey 选项,当我单击标题时它会起作用。我想在页面加载时根据customkey 自动排序。我怎样才能做到这一点?我想使用这个特定的脚本。我尝试了window.onload,但没有成功。

【问题讨论】:

    标签: javascript html sorting sorttable.js


    【解决方案1】:

    加载页面后,只需点击您要排序的标题列即可。尝试以下javascript 代码。我假设页面中只有一个表。也许您需要更具体地使用getElementsByTagNamegetElementById[1] 是列号。在此之前您不需要附加点击处理程序,因为该任务由 sorttable.js 的代码完成。

    <script src="js/sorttable.js"></script>
    <script>
        window.onload = function() {
            (document.getElementsByTagName( 'th' )[1]).click();
        };
    </script>
    

    【讨论】:

      【解决方案2】:

      我解决了这个问题略有不同。在我想要点击页面加载的任何表头上,我添加了data-autoclick="true"。然后在我的主应用程序 JavaScript 中,我添加了

      <script>
          window.onload = function() {
              $('[data-autoclick="true"]').click();
          };
      </script>
      

      【讨论】:

        【解决方案3】:

        如何使用

        table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after { 
                content: " \25B4\25BE" 
            }
        

        在动态表中。

        【讨论】:

          猜你喜欢
          • 2016-11-30
          • 2022-12-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-11-21
          • 2016-01-06
          相关资源
          最近更新 更多