How to Hide && Show GridView rows onclick of header element with Javascript?

后端 未结 1 878
我寻月下人不归
我寻月下人不归 2021-01-26 12:13

I have a GridView that has a structure like this:

  • group-header

    • dept-header

      • (some person entity)
      • (some person entity)
相关标签:
1条回答
  • 2021-01-26 13:00
    $(function () {
            $('.group-header').click(function () {
                $(this).children('.dept-header').each(function () {
                   $(this).slideToggle();
                })
            });
        });
    
    
     $(function () {
            $('.group-header').click(function () {
                $(this).children('.dept-header').each(function () {
                    var el = this;
                    if (el.style.display != 'none') {
                        el.style.display = 'none';
                    }
                    else {
                        el.style.display = '';
                    }
                })
            });
        });
    **UPDATE :** 
     $(function () {
        $('.group-header').click(function () {
            $(this).nextUntil('.group-header').each(function () {
                var el = this;
                if (el.style.display != 'none') {
                    el.style.display = 'none';
                }
                else {
                    el.style.display = '';
                }
            })
        });
    });
    

    EDIT

    $(function () {
                          $('.group-header').click(function () {
                              var parentgrpHeader = $(this);
    
                              $(this).nextUntil('.group-header').each(function () {
                                 !parentgrpHeader.hasClass("toggle") ?  $(this).hide() : $(this).show();
                              });
    
                              parentgrpHeader.toggleClass('toggle');
                          });
    
    
                           $('.dept-header').click(function () {
                              $(this).toggleClass('collapsed').nextUntil('.dept-header, .group-header').toggle();
                          });
    
    
                  });
    
    0 讨论(0)
提交回复
热议问题