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

Explicitly set a column width with JavaScript

5 Answers 1007 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zach
Top achievements
Rank 1
Zach asked on 21 Nov 2014, 10:01 PM
Does anyone know if there is a way to explicitly set the column width with JavaScript where width = 'x' and column name = 'z'?

Thanks,
Zach

5 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 25 Nov 2014, 01:07 PM
Hello Zach,

Currently, the Grid's API does not provide a method for changing a column's width, however you could achieve similar results using the setOptions method. For example: 
var grid = $("#myGrid").getKendoGrid();
grid.columns[0].width = 100;
grid.setOptions({columns: grid.columns});

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Zach
Top achievements
Rank 1
answered on 25 Nov 2014, 11:37 PM
Hi Alexander,

I've attempted to implement your snippet via JSFiddle. It isn't working as I've got it coded, currently.

Any thoughts?

Thanks!
0
Zach
Top achievements
Rank 1
answered on 26 Nov 2014, 05:03 PM
Looks like I wasn't referencing the latest Kendo UI build in the fiddle. Working example here.

Thanks for the help!
0
Zach
Top achievements
Rank 1
answered on 26 Nov 2014, 05:44 PM
I can't seem to get the columns to shrink smaller than the width of the text in the cells. Do you know if there's an override to this?
0
Alexander Popov
Telerik team
answered on 27 Nov 2014, 03:25 PM
Hi Zach,

Setting a smaller size than would require the Grid's scrollable option to be enabled, otherwise the total with of the column would always be equal to the Grid's content table width.
More information on that topic can be found here.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Zach
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Zach
Top achievements
Rank 1
Share this question
or