jQuery Tablesorter-如何动态关闭过滤器



我正在使用TableSorter版本2.28.1。我有过滤器打开。

 widgets: ["zebra", "filter"]

我希望能够在显示表之前关闭过滤器或在代码中打开过滤器。这是基于上一页传来的参数。

我正在使用C#,并且页面上的表是.NET GridView控件。

有人有任何想法吗?

使用applywidgetID和removewidget方法的组合切换过滤器窗口小部件(demo):

html

<button type="button">Add Filter</button>
<table class="tablesorter">...</table>

脚本

$(function() {
    var $table = $('table');
    $('button').click(function(){
    var btn = $(this),
        addWidget = /add/i.test(btn.text());
    if (addWidget) {
      btn.text('Remove Filter');
      $table.trigger('applyWidgetId', 'filter');
    } else {
      btn.text('Add Filter');
      $table.trigger('removeWidget', 'filter');
    }
    return false;
  });
  $table.tablesorter({
    theme: 'blue',
    widgets: ['zebra']
  });
});

谢谢@mottie。我需要的是" applywidgetId"。对我来说,这有点简单。我只需要根据变量的值在初始化时打开或关闭过滤器即可。这就是我所做的...

widgets: ["zebra"],
initialized: function (table) {                
    if ('<%= showFilter %>' == 'Y')
    {
        $(table).trigger('applyWidgetId', 'filter')
    }

最新更新