2012-12-18 2 views
0

jquery tablesorter를 사용하여 테이블을 정렬하고 있습니다. 나는 내 질문에 구글을 시도했지만, 내가 찾던 것을 찾지 못했다.테이블 정렬 방법 변경 jquery tablesorter

콘텐츠가 동적으로 변경되는 테이블이있어서 아이템 정렬 방식을 변경하고 싶습니다. 나는 테이블을 가지고

한 경우는 기본적 .tablesorter()으로 정렬 할 수있는 텍스트로 채워 나는 자리가 그래서 나는이 같은 tablesorter에 호출 할 필요가 테이블에있는 또 다른 경우에있어 : ​​

$('table').tablesorter({ 
     headers : { 
       0 : {sorter:'digit'}, 
       1 : {sorter:'digit'}, 
       2 : {sorter:'digit'}, 
       3 : {sorter:'digit'} 
     } 
    }); 

I을 표 내용을 숫자/텍스트 사이에서 전환하는 표를 다시로드하는 방법이 있습니다. 표를 정렬하는 방법을 어떻게 바꿀 수 있습니까? 예 (의사)에

:

function reloadTableData 
if table contains numbers user this tablesorter (I have a way to know if table contains numbers) 
$('table').tablesorter({ 
      headers : { 
        0 : {sorter:'digit'}, 
        1 : {sorter:'digit'}, 
        2 : {sorter:'digit'}, 
        3 : {sorter:'digit'} 
      } 
     }); 
if table contains text use ordinary table sorter 
$('table').tablesorter(); 
end 

I는 어느 문자/숫자와 테이블 데이터를 n 번을 다시 할 수있다.

나는 다음 시도했다 :

가 작동하지 않습니다 말할 필요도없이
function initTablesorter(n) { 

    switch(n) 
    { 
    case "number": 
     digitTableSorter(); 
     break; 
    case "text": 
    defaultTableSorter(); 
     break; 
    default: 

    } 
} 

function digitTableSorter(){ 
$('table').tablesorter({ 
     headers : { 
       0 : {sorter:'digit'}, 
       1 : {sorter:'digit'}, 
       2 : {sorter:'digit'}, 
       3 : {sorter:'digit'} 
     } 
    }); 
} 

function defaultTableSorter(){ 
$('table').tablesorter(); 
} 

, 나는 내가 지금 몇 시간 동안 붙어있어, 누군가가 전에이 같은 짓을 바랍니다.

+0

테이블 위 테이블 위를 재 초기화하는 작업이 효과가 있습니까? 테이블 바인더를 리 바인드하기 전에 바인딩 해제하려고 할 수 있습니다. http://stackoverflow.com/questions/8171530/remove-jquery-tablesorter-from-table을 보시오 – iappwebdev

+0

@ 시몬 이봐, 고마워서 대답했다. 대답을 받아 들일 수있다. –

답변

1

당신이 테이블에 tablesorter에를 reinitialising 때문에 그래서 작동하지? 테이블 바인더를 리 바인드하기 전에 바인딩 해제하려고 할 수 있습니다.

$('table') 
.unbind('appendCache applyWidgetId applyWidgets sorton update updateCell') 
.removeClass('tablesorter') 
.find('thead th') 
.unbind('click mousedown') 
.removeClass('header headerSortDown headerSortUp'); 

Remove jQuery tablesorter from table을 살펴보십시오.

0

난 당신이 찾고있는 생각 - 당신이 얻을 MetatData plugin을 필요로 할 일 수업이 좋아하는 "{sorter: 'digit'}"

http://tablesorter.com/docs/example-trigger-sort.html

$("#trigger-link").click(function() { 
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero 
    var sorting = [[0,0],[2,0]]; 
    // sort on the first column 
    $("table").trigger("sorton",[sorting]); 
    // return false to stop default link action 
    return false; 
}); 
+1

[Download ] (http://tablesorter.com/docs/index.html#Download) 섹션에 다음 메시지가 표시됩니다. jQuery Metadata 2.1 (3,7kb 인라인 옵션 설정에 필요). 거기에있는 "인라인 옵션"링크가 메타 데이터 예제를 참조하는 것을 볼 수 있습니다. – Mottie

관련 문제