This is a migrated thread and some comments may be shown as answers.

autoFitColumn functionality?

2 Answers 1567 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Roth
Top achievements
Rank 1
Brian Roth asked on 30 Mar 2015, 08:07 PM
Hello,

I noticed this blurb in the latest release notes and it piqued my curiosity:
    Auto-fit for column width, depending on cell text content

I couldn't find anything in the documentation, so I took a look through the grid code and found the autoFitColumn method.  Are there any suggestions or documentation for using this method?  Currently most of our grid columns have an explicitly defined width which in some cases may be a lot wider than what is actually needed based on the particular data being viewed.  What I'd like to be able to do is after the grid has been bound to the data is to automatically resize the column widths so that they are only as wide as necessary.  It seems like this method might be able to accomplish that, but I was looking for some guidance on if this would be a viable approach or if this method wasn't intended for this purpose.  Thanks!

Regards,
Brian

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 01 Apr 2015, 12:51 PM
Hello Brian,

Please check

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-resizable

http://demos.telerik.com/kendo-ui/grid/column-resizing

and

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-autoFitColumn

(for your peace of mind, I should clarify that the information in the third link has just been added)

Note that if you autofit all columns at the same time, you are likely to end up with empty space on the right side of the Grid, which does not look good. Also, autofitting all columns one after the other is an "expensive" operation from performance point of view, expecially if you have a large number of rows. A better approach would be to use a non-scrollable Grid with automatic table layout.

http://docs.telerik.com/kendo-ui/web/grid/appearance#column-widths

Regards,
Dimo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Roth
Top achievements
Rank 1
answered on 02 Apr 2015, 07:07 PM
Hi Demo,

Thanks for the info!  We really do need the grids to be scrollable, so I'll probably look at just autosizing the 2 or 3 columns that tend to have the largest variance in data width and see how the performance is.  I appreciate the advice.

Regards,
Brian
Tags
Grid
Asked by
Brian Roth
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Brian Roth
Top achievements
Rank 1
Share this question
or