Can I define a lightning:datatable column to default to "Wrap Text"?
To hide drop-down box:
.THIS .slds-button_icon-bare{
display: none;
}
To set default 'wrap text' logic:
.THIS .slds-truncate {
text-overflow: inherit;
white-space: normal;
word-wrap: break-word;
overflow-wrap: break-word;
}
Of course it's not most sophisticated way but what else we can do..
With the Spring 2020 release, we can now use an attribute called wrapText.
var columns = [
{ label: 'Description', fieldName: 'description', type: 'text', wrapText: true },
//other column data
];
https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_aura_components.htm
Then to get rid of the column header where the user chooses between clipped or wrapped text, use CSS:
.THIS .tableHeader thead th button {
visibility: hidden;
display: none;
}
Component markup:
<lightning:datatable
class="tableHeader"
aura:id="tableIdExample"
columns="{! v.columns }"
data="{! v.data }"
keyField="Id"
onsave ="{!c.onSave}"
hideCheckboxColumn="true"
onrowaction="{! c.handleRowAction }" />
In lightning:datatable there is no attribute to set "text wrapping". So, you can only set wrapping by clicking from the drop-down menu on the column header. Content is clipped by default if the number of characters is more than what the column width can hold. As per latest release Notes, it is not possible.