Tablesorter: Set initial filter-select value on load

岁酱吖の 提交于 2019-12-07 12:58:17

问题


I have a tablesorter table where a column uses the filter-select and filter-onlyAvail classes. What I'm trying to do is pre-filter that column on one of the values in the drop-down select.

I have tried setting it in the data-placeholder attribute but that doesn't do the trick.

I've also tried the following:

$(document).ready(function(){
    $.tablesorter.setFilters($("#table"),['','','','','','','','T'],true);
});

It correctly sets the filter in the select menu but doesn't actually RUN the filter.

Any ideas?


回答1:


To initially set the filters, add the filter to a header "data-value" attribute (set by the filter_defaultAttrib widget option):

<table id="table">
  <thead>
    <tr>
      <th>...</th>
      ...
      <th data-value="T">...</th>
  </thead>
  <tbody>
  ...
  </tbody>
</table>

You can see an example here in the Age column where <30 is initially set.



来源:https://stackoverflow.com/questions/32034991/tablesorter-set-initial-filter-select-value-on-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!