2010-06-08 99 views
1

我使用http://tablesorter.com/docs/example-options-headers.html動態jQuery的表格排序

$("#sort-table").tablesorter( 
     {headers: { 

      0: { 
       sorter: false 
       }, 

      dynamic_value: { 
        sorter: false 
      } 
     } 
    }); 

如何傳遞Dynamic_value例如從$( '頭')。長度是多少?

<thead> 
    <tr> 
     <th width="20"><?php echo $check;?></th> 
     <th class="header">FullName</th> 
     <th class="header">Rank</th> 
     <th class="header">Email</th> 
     <th class="header">Position</th> 
     <th width="15"></th> 
    </tr> 

回答

4

我想你想申請sorter: false某列,其數量已被動態計算。據我所知,JavaScript不容許任何直接的語法,所以你必須去與以下幾點:

headerset = { 
       0: { 
        sorter: false 
       } 
      // any other static column here 
      }; 
// repeat the following line for each dynamic value 
headerset[dynamicvalue] = { sorter: false }; 
// the variable headerset now contains the header settings 
// you can apply them to the tablesorter 
$("#sort-table").tablesorter({ headers: headerset }); 

這不是優雅,但它應該工作。

+0

謝謝。我工作得如我所願。 – kn3l 2010-06-09 01:44:48

0

解決方案上面的查詢是如下:

$(document).ready(function() 
{ 
    // extend the default setting to always sort on the first column 
    $.tablesorter.defaults.sortList = [[0,0]]; 
    var newheader={ 
     1:{sorter:false}, 
     4:{sorter:false} 
    }; 
    $(".tablesorter").tablesorter({headers:newheader}); 
}); 

我們還可以擴展使用JSON字符串如下所示的選項。 我已經創建了一個bin上的解決方案http://codebins.com/codes/home/4ldqpcd