Saturday, December 10, 2011

Expand All / Collapse All panes in Ajax Accordion Extender


There is no direct way to Expand/Collapse all panes in Accordion Extender. Using following java script, Accordion can be Expand/Collapse all panes in one click.

<script type="text/javascript">
    function pageLoad()
    {
    collapseAll();
    }
    function collapseAll()
    {
        var behavior = $get("<%=UserAccordion.ClientID%>").AccordionBehavior;
            for (var i = 0; i < behavior._panes.length; i++) {
                behavior.get_Pane(i).content.style.display = 'none';
                behavior.get_Pane(i).content.height = 0;
                behavior.get_Pane(i).content.style.height = '0px';
            }           
            behavior.set_SelectedIndex(-1);
    }
    function expandall()
    {
       var behavior = $get("<%=UserAccordion.ClientID%>").AccordionBehavior;
            for (var i = 0; i < behavior._panes.length; i++) {
                behavior.get_Pane(i).content.style.display = 'block';
                behavior.get_Pane(i).content.height = behavior.get_Pane(i).content.scrollHeight;
                behavior.get_Pane(i).content.style.height = behavior.get_Pane(i).content.scrollHeight + 'px';
            }

    }
    </script>



5 comments:

  1. When I tried this code, the expandAll function expanded all my panes, but didn't display their contents (only whitespace where the content should be). So I tried changing 'block' to 'inline' in line 5 of expandAll, and that worked, it displayed all panes perfectly.

    ReplyDelete
    Replies
    1. As an update to my previous comment, since then I tried it across multiple browsers. I found that changing 'block' to 'inline' works in Chrome and IE, but fails in Firefox, which only displays whitespace where the content should be. I looked at the HTML code and found that somehow, "style='display: none;'" is being inserted on the accordion pane div. Any ideas why this would happen on Firefox and not Chrome or IE?

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Try this snippent;

    var FIREFOX = /Firefox/i.test(navigator.userAgent);
    for (var i = 0; i < behavior._panes.length; i++) {
    if (FIREFOX) {
    behavior.get_Pane(i).content.style.display = 'block';
    behavior.get_Pane(i).content.style.opacity = "100";
    }
    else {
    behavior.get_Pane(i).content.style.display = 'inline';
    }
    behavior.get_Pane(i).content.height =
    behavior.get_Pane(i).content.scrollHeight;
    behavior.get_Pane(i).content.style.height =
    behavior.get_Pane(i).content.scrollHeight + 'px';
    }

    ReplyDelete
  4. I tried the same and found working but in IE we need to double click the accordian content instead of single click .Help me pls

    ReplyDelete

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...