2013-05-08 67 views
1

是否可以使用tablesorter过滤器小部件从表格单元格中排除子元素?使用tablesorter过滤器小部件从表格单元格中排除子元素

I.e.如果在过滤器框中键入Mia,我只希望显示第二行。但是,过滤器小工具的默认行为是搜索表格单元格的所有内容,因为该行1也显示为Mia的也是<div class="information">第1行中

<table> 
    <thead> 
     <tr> 
      <td>Name</td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td> 
       John 
       <div class="information"> 
        He is 25 years old and has a sister called Mia 
       </div> 
      </td> 
     </tr> 
     <tr> 
      <td>Mia</td> 
     </tr> 
    </tbody> 
</table> 

我使用$('table').tablesorter({ widgets: ['filter'] });到启动tablesorter。

如果这是不可能的,我必须将其他地方的每个单元格的附加信息。

回答

1

你可以用filter_useParsedData选项(demo)一起使用textExtraction功能的组合:

$('table').tablesorter({ 
    theme: 'blue', 
    textExtraction: { 
     0: function (node) { 
      return $(node).contents().filter(function() { 
       return this.nodeType === 3; 
      }).text(); 
     } 
    }, 
    widgets: ['zebra', 'filter'], 
    widgetOptions: { 
     filter_useParsedData: true 
    } 
}); 
+0

谢谢,它的工作真的很好! =)小心解释textExtraction函数中发生了什么? – Andreas 2013-05-08 23:19:47

+0

好的,当我仔细观察它时,它实际上非常简单。再次感谢! :) – Andreas 2013-05-08 23:27:05

相关问题