Expand/Collapse All

Is there a way to add expand/collapse all to the grid detailed row and do it in the header like the screenshot below?

https://ej2.syncfusion.com/angular/documentation/grid/row/detail-template



7 Replies

VS Vikram Sundararajan Syncfusion Team July 3, 2023 08:30 AM UTC

Hi Iana Stapelberg,


Greetings from Syncfusion support,


Based on your requirement wants to expand/collapse all to the grid detailed row and do it in the header. You can use the detailExpandAll method to expand all the details rows. And use the detailCollapseAll method to collapse all the expanded rows. Please refer the below code snippet, documentation and sample for more information,


[app.component.ts]

 

 public created() {

    var btn = createElement('span', { className: 'e-icons e-small e-plus'  });

    btn.onclick = () => {

      if (this.detailState) {

        this.grid.detailCollapseAll();

        this.detailState = false;

      } else {

        this.grid.detailExpandAll();

        this.detailState = true;

      }

    };

    this.grid.element.querySelector('.e-detailheadercell').appendChild(btn);

  }

 


Sample:  https://stackblitz.com/edit/angular-boejtr?file=src%2Fapp.component.html,src%2Fapp.component.ts


detailExpandAll- https://ej2.syncfusion.com/angular/documentation/api/grid/#detailexpandall

detailCollapseAll- https://ej2.syncfusion.com/angular/documentation/api/grid/#detailcollapseall


If you require further assistance, please do not hesitate to contact us. We are always here to help you.

Regards,

Vikram S



IS Iana Stapelberg August 1, 2023 09:18 PM UTC

Thank you!

I made some small changes and it works almost as expected.

Are there any expanding/collapsing events that are triggered when a detailed row is expanded/collapsed?




VS Vikram Sundararajan Syncfusion Team August 2, 2023 08:24 AM UTC

Hi Iana Stapelberg,


We have reviewed your query about event triggers when expanding and collapsing the hierarchical grid. We suggest you use "detail-state-change" event in grid.on() function and check whether it is in expanded state using isExpanded property. We have attached a code snippet and sample for your reference.


  [app.component.ts]

 

public detailDataBound(){

    console.log('Expanded');

  }

  public load() {

    this.grid.on('detail-state-change', (args) => {

      console.log(args)

      if (args.isExpanded) {

        console.log('Expanded');

      } else {

        console.log('Collapsed');

      }

    });

  }


Sample: https://stackblitz.com/edit/angular-boejtr-9elqaa?file=src%2Fapp.component.html,src%2Fapp.component.ts


Please let us know if you need any further assistance.


Regards,

Vikram S



SB Stanislav Bizdiga August 4, 2023 01:55 PM UTC

Hi Vikram,


Is there a similar event to 'detail-state-change' for a TreeGrid with details?

Attempting the solution on a grid works, but doesn't seem to function on a TreeGrid.

Also property 'on' does not exist on type 'TreeGridComponent'.

How would one apply the solution for TreeGrid?



VS Vikram Sundararajan Syncfusion Team August 8, 2023 01:55 PM UTC

Hi Iana Stapelberg,


Query #1 : Is there a similar event to 'detail-state-change' for a TreeGrid with details?

Query #2 : Also, property 'on' does not exist on type 'TreeGridComponent'.


There is no event like 'detail-state-change' in treegrid. Instead, we can use this event with ‘on’ function from grid’s instance. Kindly refer to the following code.


  [app.component.ts]

 

public load() {

    this.treegrid.grid.on('detail-state-change', (args) => {

      console.log(args)

      if (args.isExpanded) {

        console.log('Expanded');

      } else {

        console.log('Collapsed');

      }

    });

  }

 


Sample : https://stackblitz.com/edit/angular-jqr5b5-gytgcm?file=src%2Fapp.component.html


Regards,

Vikram S



UM usman malik SE October 14, 2024 02:10 PM UTC

how we can expand the and collapse rows when we have transposed the data into rows


Image_4135_1728914933087



AR Aishwarya Rameshbabu Syncfusion Team October 15, 2024 05:29 PM UTC

Hi usman malik,


Based on the provided information and the screenshot, we have observed that you are transposing the Grid data. By default, transposing Grid data is only supported for display purposes. Consequently, we cannot perform any Grid actions with this structure, including expanding or collapsing records using the Grid methods.


Regards

Aishwarya R


Loader.
Up arrow icon