[SalesForce] Can we specify a minimum height for a lightning:datatable/lightning-datatable

Problem

lightning:datatable (rendered as a lightning-datatable) places itself in a wrapper that is only exactly as big as it needs to be. If you click on a header-level action in a table with no rows, the table scrolls up, hiding the header row almost completely. If you click on an area within the lightning:datatable, it usually scrolls back down so you can see the header row, but clicking anywhere else results in an essentially blank area where the menus can no longer be seen.

SSCCE

<aura:application extends="force:slds">
    <aura:attribute name="columns" type="List" default="[ { label: 'Other' }, { label: 'Demo', type: 'action', actions: [ { label: 'Demo', name: 'demo' } ] } ]" />
    <aura:attribute name="data" type="List" default="[ ]" />
    <lightning:datatable columns="{!v.columns}" data="{!v.data}" keyField="Id" />
</aura:application>

Attempts

I tried adding various types of CSS, including a wrapper element, applying a style directly to the table, etc, but nothing seems to work.

Example Attempts

.THIS.dataTable {
  min-height: 3em;
}

    <lightning:datatable class="dataTable" columns="{!v.columns}" data="{!v.data}" keyField="Id" />

  <div class="dataTable">
    <lightning:datatable columns="{!v.columns}" data="{!v.data}" keyField="Id" />
  </div>

Since we can't really "reach" into the component any more because of how LWC works with CSS, is there a solution to this problem other than rendering dummy rows?


Demo

Demonstration of missing/scrolled header

Best Answer

It is a little bit fragile since it relies on the SLDS style class slds-table_header-fixed_container but this sets an (exaggeratedly large) min-height on the header div that gets rendered into the markup for the table.

.THIS .slds-table_header-fixed_container {
    min-height: 12em;
}

enter image description here

Related Topic