【问题标题】:jQuery Tablesorter - column not sorting alphabeticallyjQuery Tablesorter - 列不按字母顺序排序
【发布时间】:2010-06-14 20:25:30
【问题描述】:

我不确定这里出了什么问题。这是页面:http://www.utexas.edu/ssw/cswr/projects/project-list/

第一列已排序,但它没有以正确的顺序(字母顺序)返回数据。

表格本身是由一个从 WordPress 数据库中提取信息的自定义 PHP 函数生成的。我认为这可能是问题所在,但正如您所见,第四列(结束日期)排序正确。我还认为可能是第一列中的链接搞砸了,但添加来自this page 的文本提取代码完全破坏了排序。

这是我当前用来调用 Tablesorter 的 jQuery 代码:

<script type="text/javascript" id="js">

   jQuery(document).ready(function($) { 
       $(document).ready(function() {
          // call the tablesorter plugin, the magic happens in the markup
          $("#projectTable").tablesorter({ 
              // pass the headers argument and assing a object 
              //debug: true,
              //sortList: [[0,0]],
              headers: { 
                  0: { 
                  // set the column to sort as text  
                      sorter: 'text',
                  },
                  // assign the secound column (we start counting zero) 
                  1: { 
                      // disable it by setting the property sorter to false 
                      sorter: false,
                  }, 
                  // assign the third column (we start counting zero) 
                  2: { 
                      // disable it by setting the property sorter to false 
                      sorter: false
                  },
                  3: {
                        sorter:'digit'
                  }
              }


          });

               // Works only with plugin modification
                $("#projectTable").bind("sortStart",function(e) { 
                    if( $(e.target).hasClass('header') ) {
                        $("#overlay").show();
                    }
                }).bind("sortEnd",function(e) {
                    if( $(e.target).hasClass('header') ) {
                        $("#overlay").hide();
                    }
                });

         });
    }); 
</script>

感谢您的帮助!

【问题讨论】:

    标签: jquery tablesorter


    【解决方案1】:

    您需要将textExtraction 定义为complex,因为元素中有链接。

    见:http://tablesorter.com/docs/#options

    【讨论】:

    • 我尝试在上面代码中的“标题”行之前添加 textExtraction : complex,但它完全破坏了排序。我还尝试了文档中列出的关于 textExtraction 的所有示例,但它们也没有工作 - 我可能没有将它们放在正确的位置?感谢您的帮助!
    • 没关系!! :) 我在“复杂”一词周围添加了单引号,它起作用了。谢谢!
    【解决方案2】:

    问题在于它是按链接中的 URL 而不是文本排序的。

    您可能需要创建自定义排序条件(textExtraction 属性)来解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      相关资源
      最近更新 更多