2012-01-18 2 views
2

XML 파일을 테이블로 구문 분석하고 jquery tablesorter를 사용하려고합니다. 이제는 기존 테이블러가 없기 때문에 오류가 발생했기 때문에 데이터가 테이블에 채워지지만 헤더를 정렬 할 수는 없습니다. 어떤 아이디어? JS 및 HTML에 대한 코드는 아래에 나열되어 있습니다.jQuery Tablesorter가 열을 정렬하지 않음

HTML :

<html> 
<head> 
    <title>Read XML</title> 
    <script type="text/javascript" src="jquery-1.7.1.js"></script> 
    <script type="text/javascript" src="jquery.tablesorter.js"></script> 
    <script type="text/javascript" src="custom.js"></script> 
</head> 
<body> 
    <table id="table" border="1"> 
     <thead> 
      <tr> 
       <th>Item #</th> 
       <th>Shape</th> 
       <th>Weight</th> 
       <th>Color</th> 
       <th>Clarity</th> 
       <th>Price($)</th> 
      </tr> 
     </thead> 
     <tbody> 
     </tbody> 
    </table> 
</body> 
</html> 

JS :

$(document).ready(function() { 
$("#table").tablesorter(); 
$.ajax({ 
    type: "GET", 
    url: "tutorial.xml", 
    dataType: "xml", 
    success: parseXml 
}); 
$("#table").trigger("update"); 
}); 

function parseXml(xml) 
{ 
    $(xml).find("diamond").each(function() 
    { 
     $("#table tbody").after("<tr><td>" + $(this).find("id").text() + 
     "</td><td>" + $(this).find("shape").text() + "</td><td>" + $(this).find("weight").text() + 
     "</td><td>" + $(this).find("color").text() + "</td><td>" + $(this).find("clarity").text() + 
     "</td><td>" + $(this).find("price").text() + "</td></tr>"); 
    }); 
} 
+0

두 가지 오타가 코드를 수정 했습니까? – rekire

+0

그들은 tablesorter의 마지막 질문에서 함수가 아닌 문제를 해결했습니다. – Brandon

답변

1

이동이 광고 다음 parseXML 방법 끝에

$("#table").trigger("update"); 

및 변경 .after-.append

0,123,
+0

그게 나를 위해 작동하지 않았다. – Brandon

+0

'.after'를'.append'로 바꾸어 편집을 시도 했습니까? –

+0

'.after'를'.append'로 바꾸면 속임수가 쓰 였고 ... 그래서 trigger 문을 parseXml의 끝으로 이동 시켰습니다. – Brandon

2

parseXml 끝에 $("#table").trigger("update");이 있어야 tablesorter에게 테이블이 업데이트되었음을 ​​알릴 수 있습니다. ajaxRequest가 반환되기 전에 실행되면 도움이되지 않습니다.

관련 문제