swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

ngx-datatable-row-detail - "auto" height and padding calculations - virtualization on #1968

Open bonellimitch opened 3 years ago

bonellimitch commented 3 years ago

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[x] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior

You can only set a specific height for the datatable-row-detail which means you have to know how big the content of the detail is before it gets displayed.

Moreover if you use [rowHeight]="100" and the row-details provides top and bottom padding of 10px then the actual height / available space inside the row details is not 100px but 80px!

Expected behavior

Following the related issues:

Reproduction of the problem

What is the motivation / use case for changing the behavior?

I don't know the height of the component that gets loaded in the row detail. Actually, depending on the responses I receive from the BE, I need to show / hide different components (i.e: a list, a form, just some text) which have all different heights requirements.

Please tell us about your environment: Windows 10

btimfl commented 2 years ago

I'm facing the same issue, did you find any solution for this?

bonellimitch commented 2 years ago

Hi @btimfl, unluckly we stopped working on the component a while ago so I don't remember exactly if we managed to fixed it or not and we are not planning on going on with this component for now due to other priorities.

What I can tell is that by quickly testing maybe we found a way to solve it but I'm not sure. I'll share with you some code maybe it might be useful for your testing.

This is what we defined in the html template.

<!-- Accordion template -->
<ngx-datatable-row-detail [rowHeight]="getHeight()" #accordion>
  <ng-template let-row="row" let-expanded="expanded" ngx-datatable-row-detail-template>
    <div class="injector-container" #accordionContainer>
      <!-- other angular component -->
    </div>
  </ng-template>
</ngx-datatable-row-detail>

And this is how the getHeight() funcion is implemented:

  getHeight() {
    let height = this.accordionContainer;
    if (this.accordionContainer && this.accordionContainer.nativeElement.offsetHeight > 0) {
      height = this.accordionContainer.nativeElement.offsetHeight;
    }
    this.rows = [...this.rows];
    return height;
  }

So basically what id does is to calculate the height of the accordionContainer manually at runtime and the forcing the rendering of the datatable by assigning the rows again.

Hope it helps in someway! Good luck!!

btimfl commented 2 years ago

Thank you so much for replying and sharing this information. Unfortunately for me, I'm passing the template for the rowDetail from another component, and I'm facing a bunch of problems in getting the offset height due to that. I don't think I'll be able to make it work unless I define the template right in this file, which is not possible because the content of the detail row are decided based on some information I get from the backend.