首页 > 解决方案 > 表格排序器过滤器和切换隐藏行不能一起工作

问题描述

我有 tablesorter 版本,它具有与这些选项完美配合的过滤器选项

 $('.tablesorter').tablesorter({
            theme: 'blue',
            widthFixed: true,
            sortList: [[5,1]],
            widgets: ['zebra', 'stickyHeaders', 'filter'],
            widgetOptions : {
                filter_formatter : {
                    1 : function($cell, indx) {
                        return $.tablesorter.filterFormatter.select2( $cell, indx, {
                            match : false // exact match only
                        });
                    },
                    2 : function($cell, indx) {
                        return $.tablesorter.filterFormatter.select2( $cell, indx, {
                            match : true,         // adds "filter-match" to header
                            cellText : 'Match: ', // Cell text
                            width: '85%',         // adjusted width to allow for cell text
                            value: ['Lassosum','P&T','P&G'] // initial values
                        });
                    }
                },

                // option added in v2.16.0

            }

        });

所以我想最初隐藏几行,然后用复选框显示它们我有

$options.on('change', function() {
              var $elementsToToggle = $('.' + this.value);
              if (this.checked) {
                $elementsToToggle.show();
                console.log("its checked");
                $("tablesorter").trigger("updateAll");


              } else {
                  console.log("its checked");
                $elementsToToggle.each(function() {
                  var hide = true,
                      elementToToggle = this;

                  $options.each(function() {
                    var optionClass = this.value,
                        optionValue = this.checked;
                    if (elementToToggle.classList.contains(optionClass) && optionValue)
                      hide = false;
                  });

                  if (hide === true)
                    $(elementToToggle).hide();
                });
              }
            });

因此,每当我添加行时,我也在更新 tablesorter 表,但列过滤器只过滤初始行而不是动态添加的行。

标签: javascriptfilterjquery-select2tablesorter

解决方案


推荐阅读