如何设置低到高在表排序为默认值

How to set low to high in tablesorter as default ?

本文关键字:排序 默认值 何设置 设置      更新时间:2023-09-26

我正在使用tableorter jquery (jquery.tablesorter.js)来排序我的页面中的表信息。和运行良好

我添加了一个ID表排序数据如下:

<table id="keywords">

和我使用下面的脚本函数排序数据基于表:

$(function(){
$('#keywords').tablesorter(); 
});

但是我需要点击表头,数据将被排序。

我的问题是:

>如何根据表列中的数字设置Low到High作为DEFAULT

例如:当我们打开页面时,表信息会自动按照从低到高(默认)进行排序。但是如果我们点击Table head,那么它将被相应地排序。

Thanks in advance

在JavaScript中可以初始化特定列的顺序。您可以使用逗号分隔符添加多个列。

下面是单列的例子。

$(document).ready(function() { 
    // call the tablesorter plugin 
    $("yourtable").tablesorter({ 
        // sort on the first column, order asc 
        sortList: [[0,0]] 
    }); 
});

下面是多列的例子。

$(document).ready(function() { 
    // call the tablesorter plugin 
    $("yourtable").tablesorter({ 
        // sort on the first column and third column, order asc 
        sortList: [[0,0],[2,0]] 
    }); 
});

还有一种方法,通过对标记

中的元数据进行排序
<table class="tablesorter {sortlist: [[0,0],[4,0]]}" cellspacing="1"> 
参考:

设置初始排序顺序

使用元数据排序

根据列自动按默认值排序数据的最佳方法是使用以下代码:

 sortList: [[5,0]]

基于列数,如果我们有例如:一个表有10列,但我们想要排序从低到高只有列6从左到右,然后我们可以使用上面的排序列表在脚本中,如果我们有两个列,我们可以排序它们像这样:[[0,0],[1,0]]