[すべて展開]/[すべて折りたたむ] ボタンを使用して、個別に、または一度にすべて展開/折りたたむことができるアイテムのリストがあります。すべてのアイテムが折りたたまれて開始されますが、すべてのアイテムが展開されるようにアイテムを手動で展開すると、[すべて展開] ボタンが [すべて折りたたむ] に変わります。同様に、すべての項目を折りたたむと、[すべて展開] に変更されます。
したがって、個々の行をクリックするたびに、すべてのアイテムが折りたたまれているか展開されているかどうかを確認し、そうであれば、[すべて展開/すべて折りたたむ] ボタンを更新する必要があります。
私の問題は、クリックですべてのアイテムを反復処理して、それらが折りたたまれているかどうかを確認し、適切に更新する方法がわからないことです。
このための JSFiddle は次のとおりです。
これが私の現在のコードです:
var expand = true;
jQuery.noConflict();
jQuery(function() {
jQuery('[id^=parentrow]')
.attr("title", "Click to expand/collapse")
.click(function() {
jQuery(this).siblings('#childrow-' + this.id).toggle();
jQuery(this).toggleClass("expanded collapsed");
ExpandCollapseCheck();
});
jQuery('[id^=parentrow]').each(function() {
jQuery(this).siblings('#childrow-' + this.id).hide();
if (jQuery(this).siblings('#childrow-' + this.id).length == 0)
jQuery(this).find('.expand-collapse-control').text('\u00A0');
});
jQuery('#childrow-' + this.id).hide("slide", { direction: "up" }, 1000).children('td');
});
function CollapseItems() {
jQuery('[id^=parentrow]').each(function() {
jQuery(this).siblings('#childrow-' + this.id).hide();
if (!jQuery(this).hasClass('expanded collapsed'))
jQuery(this).addClass("expanded collapsed");
});
}
function ExpandItems() {
jQuery('[id^=parentrow]').each(function() {
jQuery(this).siblings('#childrow-' + this.id).show();
if (jQuery(this).hasClass('expanded collapsed'))
jQuery(this).removeClass("expanded collapsed");
});
}
function ExpandCollapseChildren() {
if (!expand) {
CollapseItems();
jQuery('.expander').html('Expand All');
}
else {
ExpandItems();
jQuery('.expander').html('Collapse All');
}
expand = !expand;
return false;
}
function ExpandCollapseCheck() {
if ((jQuery('[id^=parentrow]').hasClass('expanded collapsed')) && (expand)) {
jQuery('.expander').html('Expand All');
CollapseItems();
expand = !expand;
}
else if ((!jQuery('[id^=parentrow]').hasClass('expanded collapsed')) && (!expand)) {
jQuery('.expander').html('Collapse All');
ExpandItems();
expand = !expand;
}
}