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

"The authentication cookie fields are not defined when trying to get the authentication in the Express framework

After setting up my React client on port 3000 and Express on port 5000, I encountered an issue. When logging in, the cookie fields are set without any problems. However, when trying to retrieve the isauth value, it shows as undefined. //login log message ...

Activate a dropdown menu following the selection of a date on a calendar input using vue.js

What I need to do is have two select fields, one for 'days' and the other for 'hours'. When a day is selected, the user should then be able to choose between two available time slots. If they choose day two, the available time slots sh ...

Attempting to implement endless scrolling functionality using rxjs and angular 2 framework

I'm struggling to understand how I can incorporate stream data into my infinite scroll feature. First, I define my observable variable and page offset: products$; offset: number = 0; Next, I create an observable using one of my services: this.prod ...

A guide on looping through an array of objects to add information to a nested array in MongoDB

Currently, I am in the process of developing a blog application and working on an online editor feature. The schema I'm using for this project is outlined below: var blogSchema = restful.model('blog-schema', mongoose.Schema({ title: Str ...

how to use AngularJS filter and ng-options to format specific options as bold in a select dropdown

I am currently utilizing AngularJS ng-options to populate specific select elements. I am interested in bolding and disabling certain options. Despite trying to achieve this using the filter along with ng-options, I have been unsuccessful so far. While I ca ...

Backbone sorting is specifically designed for organizing views within the framework

As I work on creating a sorting function in backbone, I have come across recommendations to use views to listen for changes in collections and then render the views once the collections are sorted. However, this approach does not suit my needs for two main ...

Angular 5 facing issue with loading external scripts dynamically

I have configured the external scripts in the .angular-cli.json file under the scripts property: ` "scripts": [ "../src/assets/plugins/jquery/jquery.min.js", "../src/assets/plugins/popper/popper.min.js", "../src/assets/plugins/jquer ...

Issues encountered while developing a ReactJS application using TypeScript

While attempting to create a React app using the command npx create-react-app client-app --use-npm --typescript, I expected to generate a project with TypeScript files, but instead ended up with index.js and app.js rather than index.tsx and app.tsx. Could ...

What could be causing my GET route to return an empty array?

I've been attempting to retrieve an event by its id, but for some reason, I'm receiving an empty array as a result in Postman. Below is the code snippet of my route: import { events } from '../../../db.json'; const handler = async (re ...

Generating exportable dynamic code in Javascript

Any assistance or links to similar inquiries would be greatly welcomed as I have conducted some research but am uncertain about the best approach to take in this situation. I find it difficult to articulate exactly what I need, so I have created a visual ...

Directive for creating a custom loading indicator in Angular

I have created a custom Angular element directive that displays and hides a loading indicator based on a condition from a service call. The directive is used as an element within another element. While the directive itself works correctly, the issue is tha ...

Invoking a Typescript function from the Highcharts load event

Struggling to call the TypeScript function openDialog() from the events.load of Highcharts? Despite using arrow functions, you are running into issues. Take a look at the code snippet below: events: { load: () => { var chart : any = this; ...

How to reference an image located in one folder from a page in a different folder using React

Imagine there is Folder A containing an image called 'image.jpg' and Folder B with an HTML page that needs to access the image in Folder A in order to display it. The following code successfully accomplishes this task: <img src={require(&apo ...

Guide to triggering React Material-UI modal and filling it with data from an Ajax request when a button is clicked

Despite my efforts to find a similar question, I couldn't come across one. My apologies if I overlooked it. Currently, I am working on a React Material-UI project to develop a basic web application. Within this application, there is an XGrid that disp ...

Exploring the functionalities of Express and Socket.io

I am new to creating a Node.js app using express V 3.4.8 and socket.io V 0.9.16 to display a map with markers showing where users are connecting to the site. I am doing this to learn more about node.js and how to incorporate maps into my projects. However, ...

Update the color of buttons after being clicked - Bootstrap

If I want to change the class "btn-success" to "btn-warning" or update the color code to "#ffc107" upon a successful process, how can I achieve that? Button ; <button type="submit" name="teklifver" value="Teklif Ver" class="btn btn-block btn-success" ...

This phrase cannot be invoked

My code seems correct for functionality, but I am encountering an error in my component that I do not know how to resolve. Can someone please help me with this issue? This expression is not callable. Not all constituents of type 'string | ((sectionNa ...

Exploring the Reach and Sequence of AJAX Callbacks

This particular piece of code aims to achieve three main tasks: 1) validate the online status of users, 2) retrieve their information from a slightly different URL, and 3) present both sets of data in HTML format. The implementation appears functional bu ...

When render returns another component, React does not invoke componentWillMount

Here is my code setup: const Dashboard = React.createClass({ getInitialState(){ return { user: JSON.parse(localStorage.getItem('user')) }; }, componentWillMount(){ var self = this; $.get({ url: 'http://127 ...

ERROR: PipeError - Conversion of "Invalid Date" to a date is not possible for the DatePipe

While attempting to format a date with time, I ran into an error. The way I am sending the request is as follows: created = this.datePipe.transform(dateCreated, 'yyyy-MM-ddTHH:mm'); I require the time in order to consume a service that necessi ...