2017-02-01 87 views
0

テーブルの1つの列に列フィルタが追加されたHtmlテーブルがあります。jquery.tablesorter.jsの列フィルタドロップダウンから選択したオプションを取得する方法

ドロップダウンを選択すると、選択した値を取得する方法はありますか?

いずれかのアイデアがある場合は、私にお勧めできますか?

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 
+0

あなたは組み込みのイベントの一部または外部イベントとしてそれをしたいですか? –

+0

私は外部イベントとしてのみしたいです。 – Nithya

+0

答えを投稿し、あなたに役立つかどうかを確認してください。 –

答えて

1

各フィルタは.tablesorter-filterクラスがあります。

さらに、data-column属性を持ち、その値は列のインデックスです(0は最初の列の値です)。したがって

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

ああnice..isは、余分なクラスは、テーブル内のフィルタリングされた行に追加されます..? – Nithya

+0

Amm ...私は確信していませんが、ブラウザで "inspect element"ツールをチェックするだけでいいと思います。 –

+1

私は自分のjsコードを使ってテーブルローをトグルしています。いくつかの行に共通のクラスを提供しています。両方のイベントがトリガされたときにトグリングとカラムフィルタが競合しています。 – Nithya

関連する問題