TableSorter.按下拉列表选择排序 [英] TableSorter. Sort by Dropdown selection

查看:57
本文介绍了TableSorter.按下拉列表选择排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含

ID和名称(名字+姓氏)字段.在表格上方,我有一个带选项ID,名字,姓氏的下拉列表.根据选择下拉列表应排序.我不知道如何触发基于选择的tablesort排序功能.

ID and Name (FirstName + LastName) fields. Above the table I have a dropdown list with Options ID, FirstName , LastName. Based on the selection of dropdown Table should sort. I dont know How to trigger tablesort sort function based the selection.

推荐答案

也许这就是您想要的(演示)?

Maybe this is what you wanted (demo)?

HTML

<select>
    <option value="-">Choose a column</option>
    <option value="0">column 1c</option>
    <option value="1">column 2</option>
    <option value="2">column 3</option>
    <option value="3">column 4</option>
</select>

<table class="tablesorter">
    <!-- stuff here -->
</table>

脚本

$(function(){
  $('table').tablesorter();

  $('select').change(function(){
    var column = parseInt($(this).val(), 10),
      direction = 1, // 0 = descending, 1 = ascending
      sort = [[ column, direction ]];
    if (column >= 0) {
      $('table').trigger("sorton", [sort]);
    }
  });
});

这篇关于TableSorter.按下拉列表选择排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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