We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to auto fit column from controller/razor page?


I would like to be able specify that certain columns are AutoFit from C# code. I'm aware that you can bind a Javascript function to the DataBound event, but I don't want to do this. I did not see an AutoFit property in Syncfusion.EJ2.Grids.GridColumn. Is there another way to do this?

Derek B

4 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team April 11, 2019 01:36 PM UTC

Hi Derek 

Greetings from Syncfusion support. 
It is not possible to define the auto fit column configuration at the server side. However we can override the grid method to auto fit columns by default for all grids using the below code example.   
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>  
var old = ej.grids.Grid.prototype.wireEvents;  
ej.grids.Grid.prototype.wireEvents = function() {  
  this.on('content-ready'function() {  
  }, this);  
By placing this code example after the Syncfusion script reference, there is no need to configure the grid at client side/server side to auto fit its column.   

Thavasianand S. 

DE derekb April 12, 2019 06:45 AM UTC

Hi Thavasianand,

Thanks for the tip. Although I was hoping for a property to put on the grid columns for my use case, I was able to find a client-side solution that worked just fine.

Derek B

TS Thavasianand Sankaranarayanan Syncfusion Team April 15, 2019 09:44 AM UTC

Hi Derek, 
Thank you for requesting this feature “Need to provide an API support for autofitcolumn through column property” and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts. We have added this feature request to our database. You can now track the current status of this feature request here https://www.syncfusion.com/feedback/5818/need-to-provide-an-api-support-for-autofitcolumn-through-column-property. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. Until then we suggest you use your solution.  
Thavasianand S. 

TS Thavasianand Sankaranarayanan Syncfusion Team December 13, 2019 11:37 AM UTC

Hi Derek, 
We are glad to announce that our 17.2.36 patch release has been rolled out successfully and in that release, we have added the fix for this issue “Need to provide an API support for autofitcolumn through column property”. 
We have provided autoFit property in column level API and we can set autoFit for the columns which we need in Grid. 
Thavasianand S. 

Live Chat Icon For mobile
Up arrow icon