TableSorter. Sort by Dropdown selection

大兔子大兔子 提交于 2019-12-01 06:11:55

问题


I have a simple table that contains

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.


回答1:


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>

Script

$(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]);
    }
  });
});



来源:https://stackoverflow.com/questions/9382669/tablesorter-sort-by-dropdown-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!