2014-05-21 1 views
1

jquery 테이블 정렬 플러그인을 사용하고 있습니다.Jquery - 모든 열의 특성을 기반으로 정렬

테이블 열은 SQL 쿼리를 기반으로 생성됩니다.

속성 값에 따라 정렬 (오름차순 및 내림차순) 할 수 있습니까?

참고 : 테이블 열이 mulitiple (일부 열 50 열)을 생성하므로 동일한 열 이름을 기반으로 모든 열을 정렬해야하므로 다음 코드를 사용하고 싶지 않습니다. 당신이 tablesorter에 내 포크를 사용하는 경우이 테이블에서 사용하는 어떤 데이터 속성

$.tablesorter.addParser({ 
    // set a unique id 
    id: 'myParser', 
    is: function(s) { 
     // return false so this parser is not auto detected 
     return false; 
    }, 
    format: function(s, table, cell, cellIndex) { 
     // get data attributes from $(cell).attr('data-something'); 
     // check specific column using cellIndex 
     return $(cell).attr('data-something'); 
    }, 
    // set type, either numeric or text 
    type: 'text' 
    }); 

답변

2

, 당신은에 textAttribute option을 설정할 수 있습니다. 기본적으로는 data-text로 설정 : 셀은 다음 data-text 대신 "최초"의 값을 사용하여 정렬됩니다

<td data-text="1">First</td> 

.

+0

안녕하세요, 제 경우에는 테이블 열이 쿼리 (mysql-database)를 기반으로 생성됩니다. 그래서, 나는이 방법이 내 경우에는 불가능하다고 생각합니다. http://mottie.github.io/tablesorter/docs/example-option-text-extraction.html – RSKMR

관련 문제