Accordion

in namespace DotVVM.Framework.Controls.Bootstrap

Wraps a group of CollapsiblePanel controls to create an accordion-like behavior.

Usage & Scenarios

Wraps a group of CollapsiblePanel controls to create an accordion-like behavior. When you expand one of the panels inside, the others will collapse. Only one panel can be expanded at the same time.

https://getbootstrap.com/docs/3.3/javascript/#collapse-example-accordion

Sample 1: Accordion Control

To use this control, just place several CollapsiblePanels inside the Accordion control.

In the most common scenario, you need the first panel to be expanded while the others are collapsed.

<bs:Accordion>
  
  <bs:CollapsiblePanel Type="Warning" IsCollapsed="false">
    <HeaderTemplate>
      Collapsible Panel Number 1
    </HeaderTemplate>
    <ContentTemplate>
      This is panel body.
    </ContentTemplate>
    <FooterTemplate>
      Footer.
    </FooterTemplate>
  </bs:CollapsiblePanel>

  <bs:CollapsiblePanel Type="Danger">
    <HeaderTemplate>
      Collapsible Panel Number 2
    </HeaderTemplate>
    <ContentTemplate>
      This is panel body.
    </ContentTemplate>
  </bs:CollapsiblePanel>

  <bs:CollapsiblePanel Type="Warning">
    <HeaderTemplate>
      Collapsible Panel Number 3
    </HeaderTemplate>
    <ContentTemplate>
      This is panel body.
    </ContentTemplate>
  </bs:CollapsiblePanel>
  
</bs:Accordion>

Sample 2: Data-binding the CollapsiblePanels

You can data-bind the panels using the Repeater control and use the ExpandedPanelIndex property to determine which panel is currently expanded.
When none of the panels is expanded, the value of this property will be -1.

Because we don't want the Repeater to place the panels inside one <div> element, we are using the RenderWrapperTag property to modify the default behavior.

<bs:Accordion ExpandedPanelIndex="{value: Index}">

  <dot:Repeater DataSource="{value: Panels}" RenderWrapperTag="true">
    <ItemTemplate>
      
      <bs:CollapsiblePanel>
        <HeaderTemplate>
          <dot:Literal Text="{value: Header}" />
        </HeaderTemplate>
        <ContentTemplate>
          <dot:Literal Text="{value: Text}" />
        </ContentTemplate>
      </bs:CollapsiblePanel>
    
    </ItemTemplate>
  </dot:Repeater>

</bs:Accordion>

<p>Expanded panel index: {{value: Index}}</p>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.Accordion.sample2
{
    public class ViewModel
    {
        public int Index { get; set; } = 1;

        public PanelData[] Panels { get; set; } =
        {
            new PanelData("Footer 1", "Header 1", "Text 1"),
            new PanelData("Footer 2", "Header 2", "Text 2"),
            new PanelData("Footer 3", "Header 3", "Text 3")
        };
    }

    public class PanelData
    {
        public string Text { get; set; }
        public string Header { get; set; }
        public string Footer { get; set; }

        public PanelData()
        {
        }

        public PanelData(string footer, string header, string text)
        {
            Footer = footer;
            Header = header;
            Text = text;
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon ExpandedPanelIndex Int32 Gets or sets the index of the CollapsiblePanel which is currently expanded.
attribute
inner element
static value
bindable
default
-1

HTML produced by the control