2017-10-30 2 views
2

이 jQuery 테이블orter를 사용하고 있습니다 : https://mottie.github.io/tablesorter/docs/index.html. 본인은 다음과 같이 분류를 intitialize :jQuery tablesorter로 전체 클릭 대신 버튼 클릭을 정렬 할 수 있습니까?

$('.sortable').tablesorter(); 

내 표는 다음과 같습니다

<table class="sortable" id="list-users"> 
    <thead> 
     <tr> 
      <th> 
       <div class="sorter"></div> 
       ID 
      </th> 
      <th> 
       <div class="sorter"></div> 
       Name 
      </th> 
      <th> 
       <div class="sorter"></div> 
       Birth date 
      </th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
... 

기본 동작은 다음과 같다 : 나는 일 태그를 클릭하면 테이블이 정렬됩니다에 따라 기둥. 좋습니다.

하지만 대신 div.sorter를 클릭하면 이벤트가 트리거됩니다. 누군가 어떻게 할 수 있는지 알고 있습니까? 나는이 시도 : 당신이 THEAD에서 이벤트를 트리거 할 때

$('table').find('th:eq(columnNumber)').trigger('sort'); 

하지만 그건 물론 기본 이벤트를 해제하지 않는이 유용합니다.

감사합니다.

답변

1

실제로이 요소에는 정렬을 트리거하는 요소를 정의 할 수있는이 선택기가 있습니다. 프로젝트 문서의 Here's an example. 마크 업에 적용하면 다음과 같이 보일 수 있습니다.

$(function() { 
    // call the tablesorter plugin 
    $(".sortable").tablesorter({ 
     selectorSort : 'div.sorter' 
    }); 
}); 
+0

완벽하게 작동합니다. 감사합니다. – Glandalf313

관련 문제