如何从jquery.tablesorter.js中的列过滤器下拉列表中获取所选选项

时间:2017-02-01 09:33:46

标签: javascript jquery html

我有一个Html表,其中为表的一列添加了列过滤器。

选择下拉列表后如何获取所选值?

如果有人有任何想法,你能建议我吗?

HTML:

<table id="maintable" class="tablesorter custom-popup">
        <thead>
        <tr>
            <th class="filter-false">S.no</th>
            <th class="filter-false">name</th>
            <th class="filter-select" data-placeholder="Select All">Department</th>
            <th class="filter-false">Age</th>
            <th class="filter-false">Section</th>
        </tr>
        </thead>
        <tbody>
         //table body
</table>

JS

$(function() {
    /*** custom css only button popup ***/
    $(".custom-popup").tablesorter({
        headers: {2: {sorter: 'name'} },
        sortList: [[1,0],[2,0],[5,0],[3,0]],
        theme: 'blue',
        widgets: ['zebra', 'columnSelector', 'stickyHeaders','sort2Hash', 'filter'],
        widgetOptions : 

        filter_cssFilter: '', // or []
            // if true, a filter will be added to the top of each table column;
            // disabled by using -> headers: { 1: { filter: false } } OR add class="filter-false"
            // if you set this to false, make sure you perform a search using the second method below
       filter_columnFilters: true

1 个答案:

答案 0 :(得分:1)

每个过滤器都有一个.tablesorter-filter类。

此外,它具有data-column属性,其值是列的索引(0是第一列的值)。

因此:

$('.my-custom-button').click(function(){
  var filterValue = $('.tablesorter-filter[data-column=2]').val();
});