ghiscoding / slickgrid-universal

Slickgrid-Universal is a monorepo which includes all Editors, Filters, Extensions, Services related to SlickGrid usage and is also Framework Agnostic
https://ghiscoding.github.io/slickgrid-universal/
Other
90 stars 29 forks source link

Row Detail View adding extra rows in excel export #390

Closed RasmusBergHogia closed 3 years ago

RasmusBergHogia commented 3 years ago

I'm submitting a Bug report

Your Environment

Software Version(s)
Slickgrid-Universal 0.14.1
Slickgrid-Universal Excel-Export 0.14.1
TypeScript 4.3.4
Aurelia-Slickgrid 3.7.1

I have test this on Aurelia Slickgrid source code with adding Slickgrid-Universal Excel-Export on example 19.

Added to options:

enableExcelExport: true,
excelExportOptions: {
  format: FileType.xlsx
},
registerExternalResources: [new ExcelExportService()]

Describe the Bug

If you expand row details view and then export to excel, you get extra rows in excel document.

Steps to Reproduce

  1. Add both Excel Export and Row Details View to a grid.
  2. Expand one or more rows details views.
  3. Click export to excel in menu.

Expected Behavior

You get original (filtered) rows in excel only.

Current Behavior

You get the hidden extra rows which is add for row details views in the excel file.

Screenshot_229

Rows added (visible by I hide row details view): Screenshot_230

Result in excel: Screenshot_228

Possible Solution

For some reason the extra rows has what I think empty dataview inside of them: Screenshot_231

So one solution could be that ignore items with getItem in them in method pushAllGridRowDataToArray of excelExport.service.ts

private pushAllGridRowDataToArray(originalDaraArray: Array<string[] | ExcelCellFormat[]>, columns: Column[]): Array<string[] | ExcelCellFormat[]> {
  const lineCount = this._dataView.getLength();

  // loop through all the grid rows of data
  for (let rowNumber = 0; rowNumber < lineCount; rowNumber++) {
    const itemObj = this._dataView.getItem(rowNumber);
    if (itemObj && itemObj.getItem === undefined) {
      // Normal row (not grouped by anything) would have an ID which was predefined in the Grid Columns definition
      if (itemObj[this._datasetIdPropName] !== null && itemObj[this._datasetIdPropName] !== undefined) {
        // get regular row item data
        originalDaraArray.push(this.readRegularRowData(columns, rowNumber, itemObj));
       } else if (this._hasGroupedItems && itemObj.__groupTotals === undefined) {
        // get the group row
        originalDaraArray.push([this.readGroupedRowTitle(itemObj)]);
      } else if (itemObj.__groupTotals) {
        // else if the row is a Group By and we have agreggators, then a property of '__groupTotals' would exist under that object
        originalDaraArray.push(this.readGroupedTotalRows(columns, itemObj));
      }
    }
  }
  return originalDaraArray;
}
ghiscoding commented 3 years ago

@RasmusBergHogia yeah what you see in your export is actually normal, there isn't much we can do with that (I also see similar behaviors even in other paid lib like syncfusion grid) and it was also discussed in Angular-Slickgrid in this discussion thread but I'm still waiting for any code to be provided.

Your suggestion to skip these lines might be the only good solution, would you like to provide a PR (Pull Request)?

BTW, the Row Detail plugin is actually how it works, you can provide a custom panelRows number which will tell the plugin how many rows from the grid we will use. When you open the row detail, you just push the other rows down but in the back they are still just regular rows. The plugin just shows something else on top of these regular rows, so it looks like a row detail panel but in reality it's nothing more than an accumulation of regular rows which we paint something different on top of them.

RasmusBergHogia commented 3 years ago

@ghiscoding I could make a PR on that, but not today for have some other work to be done first.

ghiscoding commented 3 years ago

sure thake your time, that'd be really great to get contributions, it's always welcome šŸ˜‰

ghiscoding commented 3 years ago

@RasmusBergHogia I want to push a new release version within the next couple days and so I made the PR with your suggestion, you can take a look at PR #392

ghiscoding commented 3 years ago

@RasmusBergHogia It took me longer than expected but it's finally out for both Slickgrid-Universal and Aurelia-Slickgrid. This new version had a lot of internal changes which took longer and you can see all changes under each respective repo

Always remember to update both side at the same time.

Cheers and thanks for the feedback Happy Coding! ā­ šŸ˜„