How is it possible for the igx-expansion-panel to close when there is a nested angular accordion present?

Currently, I am faced with the challenge of closing the igx-expansion-panel within my Angular project. While everything functions smoothly with a standard panel, things get a bit tricky when dealing with nested angular accordion structures using igx-accordion. You can refer to this example for more clarity.

HTML File :

The setup involves 3 parent panels, each containing 2 child panels. I've been experimenting with collapsing and expanding these panels through a function call. While it seems to work well on parent panels, I have yet to figure out how to achieve the same functionality on child panels.

<igx-switch [(ngModel)]="singleBranchExpand">Single Branch Expand</igx-switch>
<article class="sample-wrapper">
  <button type="button" igxButton (click)="parentExpandPanel($event)">
    Parent Expand Panel
  </button>
  <button type="button" igxButton (click)="parentCollapsePanel($event)">
    Parent Collapse Panel
  </button>
  <!-- Triggering expansion in Nested Panel 2.1 under Panel 2 -->
  <button type="button" igxButton (click)="childExpandPanel(2, 1)">
    Child Expand Panel
  </button>

  <!-- Triggering collapse in Nested Panel 2.1 under Panel 2 -->
  <button type="button" igxButton (click)="childCollapsePanel(2, 1)">
    Child Collapse Panel
  </button>
<igx-accordion #accordion [singleBranchExpand]="singleBranchExpand">
    <igx-expansion-panel *ngFor="let panel of panels; let i = index" #panel>
      <igx-expansion-panel-header>
        <igx-expansion-panel-title>
          {{ panel.title }}
        </igx-expansion-panel-title>
      </igx-expansion-panel-header>
      <igx-expansion-panel-body>
        {{ panel.content }}
        <igx-accordion #nestedAccordion *ngIf="panel.nestedPanels">
          <igx-expansion-panel
            *ngFor="let nestedPanel of panel.nestedPanels; let j = index"
            #nestedPanel
          >
            <igx-expansion-panel-header>
              <igx-expansion-panel-title>
                {{ nestedPanel.title }}
              </igx-expansion-panel-title>
            </igx-expansion-panel-header>
            <igx-expansion-panel-body>
              {{ nestedPanel.content }}
            </igx-expansion-panel-body>
          </igx-expansion-panel>
        </igx-accordion>
      </igx-expansion-panel-body>
    </igx-expansion-panel>
  </igx-accordion>

TS File :

  @ViewChild('accordion', { static: true }) accordion!: IgxAccordionComponent;
  @ViewChildren(IgxExpansionPanelComponent)
  accordionPanels: QueryList<IgxExpansionPanelComponent>;

  public singleBranchExpand = false;

  // Sample data for expansion panels
  public panels = [
    { title: 'Panel 1', content: 'Content for Panel 1' },
    {
      title: 'Panel 2',
      content: 'Content for Panel 2',
      nestedPanels: [
        { title: 'Nested Panel 2.1', content: 'Content for Nested Panel 2.1' },
        { title: 'Nested Panel 2.2', content: 'Content for Nested Panel 2.2' },
      ],
    },
    {
      title: 'Panel 3',
      content: 'Content for Panel 3',
      nestedPanels: [
        { title: 'Nested Panel 3.1', content: 'Content for Nested Panel 3.1' },
        { title: 'Nested Panel 3.2', content: 'Content for Nested Panel 3.2' },
      ],
    },
    // Additional panels can be added here
  ];

  parentExpandPanel(event: any) {
    this.accordionPanels.toArray().forEach((panel) => panel.open());
  }

  parentCollapsePanel(event: any) {
    this.accordionPanels.toArray().forEach((panel) => panel.close());
  }

  //Triggering expansion in Nested Panel 2.1 under Panel 2
  childExpandPanel(panelIndex: number, nestedPanelIndex: number) {
    console.log(
      'this.accordionPanels.toArray()[panelIndex] :',
      this.accordionPanels.toArray()[panelIndex]
    );
    // const nestedAccordion =
    //   this.accordionPanels.toArray()[panelIndex].nestedPanels[nestedPanelIndex];
    // nestedAccordion.open();
  }

  //Triggering collapse in Nested Panel 2.1 under Panel 2
  childCollapsePanel(panelIndex: number, nestedPanelIndex: number) {
    // const nestedAccordion =
    //   this.accordionPanels.toArray()[panelIndex].nestedPanels[nestedPanelIndex];
    // nestedAccordion.close();
  }

For detailed information on handling nested angular accordions scenario, you can check out the documentation. However, I noticed that the documentation lacks instructions on how to specifically close or expand individual nested accordions. If anyone has insights on how to tackle this issue, please share your knowledge.

Answer №1

Have you taken a look at the igx-accordion documentation on the Infragistics website? It seems like you can simplify your code by using the expandAll() and collapseAll() methods instead of going through each panel individually and calling open(). You are already working with the panels collection, which provides access to the ExpansionPanel components that you can interact with using open() or close().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to utilize express-load in conjunction with express 4

As a beginner in NodeJS, I encountered a problem with my code. Let me show you the issue. I am trying to load the application in the MVC pattern using express-load, but I am facing an error when defining the load order. Here is the important part of app. ...

Basic AngularJS application, however I am receiving {{this is supposed to be the information}}

Building an angularjs app I have set up an asp.net mvc4 application and integrated the angularjs package using nuget. The Layout.cshtml file has been updated to look like this: <!DOCTYPE html> <html ng-app="myApp"> <head> <meta ...

What could be causing my inability to accurately guess people's ages?

My latest project involves developing a game where players have to guess names from images. Each game consists of 10 rounds, followed by a bonus round where participants must wager their points on guessing the age of the person in the image within a 2-year ...

Can Angular Universal cater to dynamic content needs?

I am considering using Angular Universal for SEO optimization and social media preview purposes. While I understand that it works well with static content, my concern lies with how it handles dynamic content. Specifically, I want search engines and social ...

The MUI classes in my React project differ between the local and live versions, creating inconsistency in styling

I've encountered a discrepancy in the Mui classes used in my React project between the local and live versions. For instance: Localhost MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeSmall MuiButton-textSizeSmal ...

What is the correct way to specify an image path for a background URL?

Currently, I am setting a background image for the hr tag using the following code: <hr style="height:6px;background: url(http://ibrahimjabbari.com/english/images/hr-11.png) repeat-x 0 0;border: 0;margin:0px!important"> However, I have now saved th ...

Parent Component in Angular 2 Fails to Refresh Upon Observable Update

I have been utilizing an Observable service to facilitate data coordination among components. Specifically, I am attempting to utilize it for managing the visibility of various HTML elements within my application. Currently, when I toggle the behavior sub ...

Tips for eliminating white frames or borders on the Mapbox canvas map

In my current project using Angular 10, I have integrated Mapbox to display path routes. Following the standard Angular practice of splitting components, I separated the map rendering component and called it into the main map component. However, I encounte ...

What is the best strategy for managing a sizable react application using react-query?

Since diving into React with functional components and react-query, I've been facing some confusion on how to properly organize my components. Typically, I design components by having a top-level component handle all data access and pass data down to ...

transfer chosen data from a text box to a dropdown menu

Looking for: I am in need of a feature where users can input a movie title in a textbox and upon clicking the "move to selectedlist" button, the entered movie title should be added to a dropdown list that displays all the movies selected by the user. Addit ...

Retrieve the heading of a click-able element using jQuery

My challenge involves a list of selectable buttons with names generated dynamically from a JSON file. Each time a button is clicked, I aim to retrieve its title, which corresponds to row["name"]. Below is my relevant code snippet and the JSON data provided ...

What is the best way to invoke a method within the onSubmit function in Vuejs?

I am facing an issue with a button used to log in the user via onSubmit function when a form is filled out. I also need to call another method that will retrieve additional data about the user, such as privileges. However, I have been unsuccessful in makin ...

What is the proper way to display the complete result of aggregating each outcome from the previous iteration within two nested queries in an array using NodeJS and Mongoose?

As a newcomer to both Stackoverflow and NodeJS/Mongoose, I apologize if I make any mistakes or break any rules. Thank you in advance. I'm looking for a function that can return all nearby products based on my current location, which is provided by th ...

Javascript Code Tweaking... Is it Just a Minor Oversight?

I've been working on incorporating a jQuery Exit LightBox into my website and came across this straightforward tutorial - The concept of the pop-up is quite clever, but I've run into an issue where it only functions properly when a visitor is at ...

Can you help me with sorting asynchronous line points for KineticJS?

For the past couple of days, I've been grappling with a peculiar issue that I found difficult to articulate in the title. The challenge I'm facing involves a KineticJs Line, which contains an array of points (line.attrs.points) represented as ob ...

Angular 4, Trouble: Unable to resolve parameters for StateObservable: (?)

I've been working on writing unit tests for one of my services but keep encountering an error: "Can't resolve all parameters for StateObservable: (?)". As a result, my test is failing. Can someone please help me identify and fix the issue? Here& ...

You are only able to click the button once per day

I am working on a button that contains numeric values and updates a total number displayed on the page when clicked. I would like this button to only be clickable once per day, so that users cannot click it multiple times within a 24 hour period. Below i ...

Serve Webpack bundle on various routes - Express Way

I recently completed a web application using an Express backend and React frontend. Upon sending a request to the Express server, it undergoes a process where the URL is checked against the backend routes. If there isn't a match, the React bundle gen ...

Troubleshooting: issues with jQuery AJAX POST functionality

My goal is to perform an AJAX operation, and while the call seems to be functioning correctly, I am encountering an issue where the response I receive is just an empty string. Surprisingly, there are no errors being displayed in the console - only an empty ...

What is the best approach to developing Vue components with unique templates while maintaining the same functionality without duplicating code?

I am working on a project to develop a custom and versatile datatable component. My goal is to be able to adjust the appearance of the datatable on each page, while maintaining consistent functionality. I want to pass data rows into the component and have ...