Hi
I want a small clarification on one of the use case related to Excel Library. (https://es.infragistics.com/products/ignite-ui-react/react/components/excel-library)
We have added GroupDescription and SummaryDescription on the grid. We want to know how can we Export this type of grid data to Excel with grouping and summary on the top of each group.
So, for this I need to know how can we achieve that.
Hoping for a positive response.
Thanks!!!
Hello Shubham,
I believe that you are probably hitting a timing issue between the actual expansion of the “special rows” and the update of the actualDataSource.count here. I think my best recommendation to ensure that all rows are expanded before trying to do an export would be to do something like this:
public onButtonClick(){ this.expandRows(); } public expandRows(){ let expansionHappened = false; for(let i=0; i<this.grid.actualDataSource.actualCount; i++){ let item = this.grid.actualDataSource.getItemAtIndex(i); if(item.$$isSpecialRow){ let expanded = this.grid.actualDataSource.getIsRowExpandedAtIndex(i); if(!expanded){ this.grid.actualDataSource.setIsRowExpandedAtIndex(i, true); expansionHappened = true; } } } if(expansionHappened){ window.setTimeout(this.onTimerTick, 1000); } else{ //do Excel export because all rows are now expanded } } public onTimerTick(){ this.expandRows(); }
Perhaps the timeout of 1000 milliseconds is a bit overkill in this case, but you can experiment with the timing of this.
Essentially, the code above will loop each record in the IgrDataGrid and look for any $$isSpecialRow items that are not expanded. If it finds one, it sets a flag that designates that it should do the loop again after a delay and after the loop finishes at that level. If no expandable record that is not already expanded is then found, you can continue with the export as this means all rows are expanded.
I hope this helps. Please let me know if you have any other questions or concerns on this matter.
Hello Andrew,
we are getting an issue here.
this.grid.actualDataSource.setIsRowExpandedAtIndex(i, true);
by doing this the grouping is expanded at one level on UI but in the actualDataSource.actualCount we are still getting an old count.
please suggest an event or any other way by which we can get the updated count.
Thanks.
Thank you for your update on this matter.
The actualDataSource of the grid will directly reflect the state of the grid with its rows, and so unfortunately, in order to get all of the rows in the grid with the method I had recommended, you will need to ensure the groups are expanded. You can expand the rows using the setIsRowExpandedAtIndex method of the actualDataSource like so, where “i” is the for-loop interation:
You can also use the getIsRowExpandedAtIndex method if you are looking to get whether or not the DataSourceSpecialRow is expanded, in which case it would need expanding. I would recommend doing this recursively such that if a row is found that needs expansion, you set something such that the loop is run again so that all of the rows are exported and allocated and then do the export.
Please let me know if you have any other questions or concerns on this matter.
Thank you for your response.
we are getting a small issue here.
Groups Collapse
Groups Expanded
If the groups are Expanded as we can see in Screnshot-2 then we are able to get all the rows and Export is working fine in that case.
But when the groups are Collapsed then we are not able to get the data inside each groups.
we have group inside group as we have set groupHeaderDisplayMode="Split". So we want to know how we can get the group inside group and the data inside each group when the groups are Collapsed.
I have been investigating into the behavior you are looking for, and you can get the group-by rows and the summaries applied to them by using the actualDataSource property of the grid and its getItemAtIndex property. If the item at the index is a group-by row, this method will return an element of type DataSourceSpecialRow, which then has a sectionValues property to get the values that were grouped on and a summaryResults collection for the summaries applied. For example, the following loop can get you all of the rows in the grid:
for(let i=0; i<this.grid.actualDataSource.actualCount; i++){ let item = this.grid.actualDataSource.getItemAtIndex(i);
if(item.$$isSpecialRow){ let specialRow: DataSourceSpecialRow = item as DataSourceSpecialRow; let groupValues = specialRow.sectionValues; let summaryValuesForGroup = specialRow.summaryResults;
} else{ //regular data item } }