TableSorter. Sort by Dropdown selection

后端 未结 1 1511
你的背包
你的背包 2021-01-14 17:49

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 o

相关标签:
1条回答
  • 2021-01-14 18:31

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

    0 讨论(0)
提交回复
热议问题