2013-01-15 82 views
1

只能用jQuery tablesorter隱藏某些列的過濾器嗎? 前三列不需要過濾器(它們只會使表格變長)。jQuery tablesorter

<table id="userTable" class="table-sorter table table-striped table-bordered"> 
    <thead> 
     <tr> 
      <th> 
       <input type="checkbox" /></th> 
      <th></th> 
      <th></th> 
      <th></th> 
      <th>Login 
      </th> 
      <th>Email 
      </th> 
      <th>Company 
      </th> 
      <th>LastName 
      </th> 
      <th>FirstName 
      </th> 
      <th>ZipCode 
      </th> 
      <th>City 
      </th> 
      <th class="filter-select" data-placeholder="Select">Country 
      </th> 
     </tr> 
    </thead> 

THX

回答

1

我解決了它通過隱藏前四個輸入字段。

// remove filters from first 4 columns 
     for (var i = 0; i < 4; i++) { 
      $('input[data-column='+i+']').hide(); 
     } 

不知道這是否正確的方法。但它的工作原理。 GRTS 丹尼

+0

+1這也可以! :) – Mottie

3

我不記得有jQuery的本地tablesorter插件,所以我覺得你用這個一個:http://tablesorter.com/docs/

如果你看看哪個下來,對配置選項。你會看到'標題'可以用來通過傳遞選項手動禁用頭部排序:{ 0: { sorter: false}, 1: {sorter: false} }這將禁用前2列的排序。

只要閱讀該文檔,你應該知道它。

+0

這確實是我使用的插件,但問題是與過濾部件, 我只需要應用過濾器的某些列,而不是前三, 還有一個屬性過濾器:假的,但問題前三列的輸入字段是禁用的,但字段本身保持可見。 –

0

如果你只想隱藏起來,那麼你可以這樣做:

// Index starts at 0 so you want to hide elem 0, 1, 2 and 3 
$('input:lt(4)').hide(); 

這隱藏第一的輸入。示例:http://jsfiddle.net/VWkJZ/

0

看起來您正在使用我的分叉爲tablesorter的過濾器小部件。因此,所有你需要做的禁用過濾特定的列是類名filter-false添加到th

<table id="userTable" class="table-sorter table table-striped table-bordered"> 
    <thead> 
     <tr> 
      <th class="filter-false"> 
       <input type="checkbox" /></th> 
      <th class="filter-false"></th> 
      <th class="filter-false"></th> 
      <th class="filter-false"></th> 
      <th>Login</th> 

,做什麼是它仍然增加了過濾器的過濾器行,但輸入是禁用。然後,你需要做的就是添加此css:

/* hide disabled filter inputs */ 
.tablesorter-filter.disabled { 
    display: none; 
} 

​​我上面描述的。