简体   繁体   English

隐藏带有过滤jQuery的表行

[英]Hide a table row with filtering jquery

I have the following example http://jsfiddle.net/zidski/MxqRu/1/ 我有以下示例http://jsfiddle.net/zidski/MxqRu/1/

When you click on 2010 I need valuation to disappear with the list items. 当您单击2010时,我需要评估以与列表项一起消失。

Here is the code which I am using to do this: 这是我用来执行此操作的代码:

$("#yearfilter a").live("click", function(e) {
                e.preventDefault();
                //var v = $(this).val();
                var v = $(this).attr("data-value");
                if(v.length > 0) {
                    $('tr.reports').show();
                    $('tr.reports ul').hide();
                    $('tr.reports ul.year-'+v).show();
                    $('tr.reports').each(function() {
                        if($('ul:visible', this).size() == 0) {
                            $(this).hide();
                        }
                    });
                } else {
                    $('tr.reports').show();
                    $('tr.reports ul').show();
                }
            });

Give each tr an ID something like id="row_2010" then look for that and hide the whole entire row at once. 给每个tr一个ID,类似id="row_2010"然后查找并立即隐藏整个整行。

UPDATE 更新

I would strongly suggest not using so many tables and use more classes to classify your data structure. 我强烈建议不要使用太多表,而要使用更多类对数据结构进行分类。 It would help your javascript be much more clean, concise and function easier. 这将帮助您的javascript更加简洁,简洁并且功能更简单。

UPDATE 更新

I adjusted all your javacsript and some of your html. 我调整了所有javacsript和一些html。 Here is a fully working example jsFiddle Demo 这是一个完整的示例jsFiddle演示

I have done it in my project something like this: 我已经在我的项目中完成了以下操作:

function toggleRow(row_id) {
    row_selector = "#row_" + row_id;
    $(row_selector).toggleClass("shown hidden")
}

Then in the CSS: 然后在CSS中:

.hidden {display:none;}
.shown {}

Then in the HTML I have alternating table rows, where the odd rows act as headings for the content in the even rows. 然后在HTML中,我有交替的表行,其中奇数行充当偶数行中内容的标题。 Clicking an odd row toggles the visibility of the corresponding even row. 单击奇数行可切换相应偶数行的可见性。

...
<tr onclick="toggleRow(17)">...</tr>
<tr class="hidden" id="row_17">...</tr>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM