function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Natalya Murphy 8Natalya Murphy 8 

Right-align column headings in lightning:datatable

I'm using a lightning:datatable to retreive data and want the date-formatted columns to be right-aligned.  I've figured out how to right-align the actual data, but the column heading is still left-aligned and I can't find any documentation on how to right-align it.

datatable definition:
<lightning:datatable
                keyField="id"
                data="{! v.eeObject.serviceBranches }"
                columns="{! v.serviceColumns }"
                hideCheckboxColumn="true"/>

...and a snippet of the column definition setting the right-align of the data:
component.set('v.serviceColumns', [
    {label: 'Entry Date', fieldName: 'serviceEntryDate', type: 'date-local', 
    typeAttributes:{ month: "numeric", day: "numeric" }, cellAttributes: { alignment: 'right' }},
    {label: 'Exit Date', fieldName: 'serviceExitDate', type: 'date-local', 
    typeAttributes:{ month: "numeric", day: "numeric" }, cellAttributes: { alignment: 'left' }}
]);

Also attaching a picture showing the problem.
Misaligned heading and data in column
Khan AnasKhan Anas (Salesforce Developers) 
Hi Natalya,

Greetings to you!

Unfortunately, there is no standard way to align table headers to right. As a workaround, you can use CSS but it might break in upcoming releases. Please refer to the below link which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/215870/lightningdatatable-with-right-to-left-does-not-display-good

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Ramesh PatnalaRamesh Patnala
I resolved my column data alignment.Thank you
Phil KammannPhil Kammann
Ramesh, did you solve the actual data alignment?  I have many stock reports in FF that are left justified, was hoping you figured out how to right justify.
Lalitha JakkaLalitha Jakka
How did you resolve your problem @Ramesh