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
Brian11Brian11 

Lightning DataTable is not resizing when window resizes.

When I resize the browser window to a larger size the lightning Datatable expands to fill the extra space. Which is working correctly

When I resize the browser window to a smaller size the lightning Datatable does not adjusts to fit the new screen size. It remains at its larger size causing the recordpage to have a horizontal scroll.

Is there a fix around this? I am using the following component:
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example

NagendraNagendra (Salesforce Developers) 
Hi Brian,

Sorry for this issue you are encountering.

May I suggest you please check with below link with a similar discussion which might help you further. Please let us know if this helps.

Thanks,
Nagendra
Brian11Brian11
Hi Nagendra,

Unfortunately the github issue example you sent did not seem to fix the problem. I believe its an issue that is still open. Any other information you have would be great.
Joe Masters 12Joe Masters 12
I know this is an old post, but I fixed this by adding an event listener in the initialization of my component that just hides and shows the datatable, and that forces it to resize.
In the controller's init, I do this:
        // This catches the 'resize' event, which is whenever the browser window resizes.
        window.addEventListener( 'resize', function(){
            // Hide/Show the datatable to get it to resize
            component.set( "v.renderDataTable","false" );
            component.set( "v.renderDataTable","true" );
        });

And then in the component, I do this:
    <aura:attribute name="renderDataTable" type="Boolean" default="true"/>
.....
            <aura:renderIf isTrue="{!v.renderDataTable}">
                <lightning:datatable        suppressBottomBar="true"      
                                            aura:id="table2"    
                                            columns="{! v.columns }"
                                            data="{! v.opendata }"
                                            keyField="Id"
                                            selectedRows="{! v.selectedRows }"
                                            onsort="{!c.updateSortingOpen}"
                                            sortedBy="{!v.sortedByOpen}"
                                            sortedDirection="{!v.sortedDirectionOpen}"
                                            oncellchange="{! c.handleSaveEdition2 }"
                                            onrowselection="{! c.updateSelected }"
                                            onrowaction="{! c.handleRowAction2 }"
                                            draftValues="{! v.draftValues }"
                                            hideCheckboxColumn="true"/>
            </aura:renderIf>

Seems to work.