How to enable auto fit Horizontal Scrollbar for an dynamically binding grid

Hi,

I need to enable the auto fit Horizontal Scrollbar for an dynamically binding grid, 
as per the " https://ej2.syncfusion.com/angular/documentation/grid/columns/?_ga=2.49539492.382750869.1600401586-1123610950.1600181766#autofit-specific-columns " link, I got to know that we can have a autofit scrollbar based on some columns (autoFitColumns), what if I have dynamically binding grid where I don't know what all columns may come and there in the grid.

so how can we achieve the autofit horizontal scroll for the grid in such scenarios.

Thanks,
Deepika.P

1 Reply 1 reply marked as answer

RS Rajapandiyan Settu Syncfusion Team September 21, 2020 03:51 PM UTC

Hi Deepika, 
 
Greetings from Syncfusion support. 

By analyzing your query, we suspect that you need to autofit the columns for dynamically binding Grid. 

Before proceeding with your requirement, we would like to share the behavior of the autoFitColumns() feature. The autoFitColumns method resizes all the columns in the Grid to fit the widest cell’s content without wrapping. You can autofit the columns at initial rendering by invoking the autoFitColumns method in dataBound event. Refer to the below code example and documentation. 


this.grid.autoFitColumns(); // auto fit all the columns in the Grid 



You can also autofit particular columns in the Grid by passing a string array of column fields in the autoFitColumns method. Refer to the below code example. 


this.grid.autoFitColumns(['ShipAddress', 'ShipName']); // auto fit particular column in the Grid 



You can achieve the same by setting the column API autoFit as true. Refer to the below code example. 


<e-column field='OrderID' headerText='Order ID' [autoFit]="true" width=200></e-column> 


 
Note: If you want to autofit a particular column by using the autoFitColumns method, then we must know the column’s field or column’s index. Else we cannot autofit the columns. 

You can get the columns in the grid by using following methods. 
 
 
please get back to us if you need further assistance with this. 
 
Regards, 
Rajapandiyan S 


Marked as answer
Loader.
Up arrow icon