Kendo React Grid - Size to Fit columns

1 Answer 71 Views
Grid
Michal
Top achievements
Rank 1
Michal asked on 22 Dec 2021, 04:07 PM | edited on 22 Dec 2021, 04:07 PM
Hello, I have a problem related to the kendo data grid. I want to implement something similar to this example, where it's possible to "Size to Fit" and "Auto-size". I was able to achieve auto-size by following this example, but I don't have any idea how to implement "Size to Fit". 
The use case is that the user resizes the grid columns to the point that grid width is less than the available width and in this case, the user is able to recover from this state by clicking the "Size to Fit" button on filling in available space. Also, some columns are locked which makes it even more difficult. 

1 Answer, 1 is accepted

Sort by
1
Accepted
Stefan
Telerik team
answered on 24 Dec 2021, 07:50 AM

Hello,

The Size to Fit option is the default option of the Grid columns where they automatically adjust based on the available space. In order to achieve that we need to reset the Grid current columns using the key property.

I made an example showcasing how to switch between fit all columns and size to fit using two buttons:

https://stackblitz.com/edit/react-cwagav-nyxo52?file=app%2Fmain.jsx

Still, if the Grid has locked columns this requires all of them to have a fixed width, which is in a conflict which the size to fit option. In that case, the size to fit button could reset the width to the original one. Another option is to remove the locked option when we want to size to fit, as in that case all columns are visible and we do not need locked columns.

Regards,
Stefan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Michal
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or