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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to auto fit column from controller/razor page?

Thread ID:





143934 Apr 11,2019 01:06 AM UTC Dec 13,2019 11:37 AM UTC ASP.NET Core - EJ 2 4
Tags: DataGrid
Asked On April 11, 2019 01:06 AM UTC


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

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 

Replied On 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

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon