Telerik Forums
Kendo UI for jQuery Forum
1 answer
2.8K+ views

The autoFitColum method sizes the chosen column to the correct size, but it also reduces all other columns to their width property as shown below. 

I created some examples to show what I'm talking about by editing autoFitColumn - API Reference - Kendo UI Grid | Kendo UI for jQuery (telerik.com)

This behavior works out in cases where the auto fit column exceeds the grid width (see figure 1), but not in cases where the the data is Smaller than the grid (see figure 2). 

The desired behavior, for me, would be for the autoFitColumn method to act like setting the width manually (see figure 3 or dojo example). I need scrollable to be true and grid width to be auto to work on any screen width. Allowing the rows to text-wrap doesn't work for scrolling large data tables.

Is figure 2 the intended behavior, and is there a way to achieve my desired behavior?

 

<div id="grid"></div><script> $("#grid").kendoGrid({ columns: [ { field: "name", width: 100 }, { field: "age", width : 50 }, { field: "quote" } ], dataSource: [ { name: "Jane Doe", age: 30, quote: "I like Pi." }, { name: "John Doe", age: 33, quote: "The FitnessGramâ„¢ Pacer Test ... ding" } ], scrollable: true, width: 'auto' }); var grid = $("#grid").data("kendoGrid"); grid.autoFitColumn("quote"); </script>

figure 1: behavior of autoFitColumn if data is longer than grid is wide.


<div id="grid"></div><script> $("#grid").kendoGrid({ columns: [ { field: "name", width: 100 }, { field: "age", width : 50 }, { field: "quote", } ], dataSource: [ { name: "Jane Doe", age: 30, quote: "I like Pi." }, { name: "John Doe", age: 33, quote: "I like Pi too." } ], scrollable: true, width: 'auto' }); var grid = $("#grid").data("kendoGrid"); grid.autoFitColumn("quote"); </script>

firuge 2: behavior of autoFitColumn if data is shorter than grid is wide


<div id="grid"></div><hr/><div id="grid2"></div><script> $("#grid").kendoGrid({ columns: [ { field: "name", width: 100 }, { field: "age", width : 50 }, { field: "quote", width : 3272 } //this width should be set by autoFitColumn instead of manually ], dataSource: [ { name: "Jane Doe", age: 30, quote: "I like Pi." }, { name: "John Doe", age: 33, quote: "The FitnessGramâ„¢ Pacer Test ... ding" } ], scrollable: true, width: 'auto' }); $("#grid2").kendoGrid({ columns: [ { field: "name", width: 100 }, { field: "age", width : 50 }, { field: "quote", width: 93 }//this width should be set by autoFitColumn instead of manually ], dataSource: [ { name: "Jane Doe", age: 30, quote: "I like Pi." }, { name: "John Doe", age: 33, quote: "I like Pi too" } ], scrollable: true, width: 'auto' }); //I left this code in a comment to make switching back and forth between my desired and actual behavior easier /*var grid = $("#grid").data("kendoGrid"); var grid2 = $("#grid2").data("kendoGrid"); grid.autoFitColumn("quote"); grid2.autoFitColumn("quote");*/ </script>

figure 3: desired visual result, but the width should be set using autoFitColumn, not manualy

 

Neli
Telerik team
 answered on 05 Jul 2021
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?