2017-10-18 73 views
1

我有彈出窗口th中的子元素。當我點擊.show_history div顯示彈出格.show_history_ctn時,觸發該列的排序。我已將.show_history的Z-index增加到9999,並且仍然會觸發排序。我還將stopPropagation添加到.show_history點擊事件,並且仍然發生排序。jQuery tablesorter子元素th禁用排序

jQuery的

$(".show_history").on("click",function(event) { 
     $(this).siblings(".show_history_ctn").find("tr").show(); 
     event.stopPropagation(); 
     if($(this).hasClass("active")) { 
      $(this).siblings(".show_history_ctn").slideUp(); 
      $(this).removeClass("active"); 
     } else { 
      $(".show_history_ctn").hide(); 
      $(".show_history").removeClass("active"); 
      $(this).siblings(".show_history_ctn").slideDown(); 
      $(this).addClass("active"); 
     } 
    }); 

$(".tablesorter").tablesorter(); 

HTML

<table class='tablesorter'><thead><tr><th><div class='show_history'>Show History</div><div class='show_history_ctn' style='display:none'>**content**</div></th><th></th></tr></thead></table> 

我該怎麼解決?我需要對列進行排序,否則我只需添加sorter:'false'

回答

1

問題是,由於重新構建表頭,點擊綁定被tablesorter刪除。你能解決這個使用下列方法之一:

  • headerTemplate選項爲空字符串("") - 這將阻止改變頭內容,因此不會破壞任何綁定。在內部,它使用innerHTML(這很可能會很快改變)來包裝內容,因爲jQuery的包裝在舊版本的IE中速度非常慢。
  • 綁定initialized回調(demo

    $(function() { 
    
        function bindLink() { 
        $('.link').click(function(e) { 
         e.preventDefault(); 
         e.stopPropagation(); 
        }); 
        } 
    
        $('table').tablesorter({ 
        theme: 'blue', 
        initialized: bindLink 
        }); 
    
    }); 
    

更新裏面的彈出鏈接:哎呀,我忘了,包括需要被添加到元素你「的tablesorter-NOSORT」的cssNoSort class name '點擊。演示鏈接更新如上。

<th>AlphaNumeric <a class="link tablesorter-noSort" href="https://google.com">test</a> 
+0

我試了演示,點擊彈出鏈接仍然被忽略,列被排序。 – mdnba50

+0

糟糕,抱歉..我已經更新了我的答案。 – Mottie