thanks as always, you dudes are the wind beneath my wings.
What I have: A <table>
that initializes with 2 columns, and a button that adds an additional column with each click (table is built using <aura:iteration>
). The table takes up the entire width of its parent <lightning:Card>
container, and the initial columns take up the width of the table. As new columns are added, all columns auto-resize to equal widths so they always take up the width of the table.
What I want: Instead of columns dynamically resizing themselves, I'd like each column to be a fixed width, filling up the table width as added, with a horizontal scroll bar appearing once the columns exceed the table width
Code:
You can see my failed attempt at using <ui:scrollerWrapper>
and slds-scrollable_x
. At one point I added a style="width:250px"
to the <th>
elements in the table body – this set the column widths fixed until they filled the table – then they started resizing again.
<ui:scrollerWrapper>
<div class="slds-scrollable_x">
<table class="slds-table slds-table_cell-buffer slds-table_bordered">
<thead>
<tr class="slds-line-height_reset">
<th class="slds-text-title_caps" scope="col">
<div class="slds-truncate" title="Entity Name">Entity</div>
</th>
<aura:iteration items="{!v.tablePeriods}" var="period" indexVar="colNum">
<th class="slds-text-title_caps" scope="col">
<lightning:input aura:id ="periodLabel" placeholder="Enter Period Label..." value="{!period.label}"/>
</th>
</aura:iteration>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.tableRows}" var="row" indexVar="rowNum">
<tr class="slds-hint-parent">
<th data-label="Entity Name" scope="row">
<div class="slds-truncate">
{!row.entityName}
</div>
</th>
<aura:iteration items="{!v.tablePeriods}" var="p" indexVar="colNum">
<th>
<lightning:select aura:id="selectList">
<option value="">choose one...</option>
<aura:iteration items="{!row.options}" var="option">
<option value="{!option.label}" selected="{!option.selected}" >{!option.label}</option>
</aura:iteration>
</lightning:select>
</th>
</aura:iteration>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</ui:scrollerWrapper>
Best Answer
Table elements always expand to take up all available space. Instead, you'll want to use normal div elements. I'm not going to try and build a perfectly working example, but you'll want to start off like this:
This will produce the effect you're looking for without the use of a table element.
Edit: Here's a really simple example app that demonstrates the logic I'm describing.