Column widths when wrap is on
I have a lot of tables with many columns mixing digital and text data. Imagine the list of parts, where you should show name, short description, brand, availability text, price, stock quantity and few parameters in one grid. Column chooser is enabled.
I set AllowTextWrap="true" for the table. I set AutoFit="true" for all columns of the table except short description to absorb redundant width for large screens. When the screen size is enough wide, everything shows well. But when the screen size goes to be tighter, text columns start to wrap their content more and more, and finally they are shrinking to zero width.
Please, make the next behavior. It is allowed to set MinWidth of column, but now it is used to mark limit of user changes of width only. Use this value to set minimum width of column when its content is wrapped. With this behavior, when MinWidth is setted, for smaller screens such columns will not wrap to infinity, but will be limited. The whole grid will expand other view boundaries and will be scrolled.
I tried to imitate this behavior myself using toggling css styles for different screen sizes, but this looks poor and not natural.
Otherwise, please, offer another solution for large grids with wrapped columns. To fix all column widths permanently is not a good idea.
- Whether did you face the problem with column width while using AllowTextWrap and AutoFit properties in small size screen?
- Whether did you faced the problem with text wrap while setting MinWidth to the column.
- Full Grid code snippets. How many column did you have in your Grid? And how did you define the Grid width?
- Video demonstration of the problem.
- Share a simple reproduceable sample if possible.
Hi Rahul,
Could you send me please the sample project with grid which contains about 7-8 columns with text and digital data mixed? I will update this project to show the trouble. Here is the screenshot.
The screenshot.
- Whether did you ensure the reported problem by setting MinWidth to the particular column?
- Whether did you set the Grid height/ width as percentage values?
- Reproduce the problem in the provided sample and revert back to us.
Hi Rahul,
I have updated your sample. Everything works more or less well till I start to use Template for Product column.
In my project I use template extremely wide because I make multi-language web-site and I should replace the content of each text column with its localized text.
As I wrote the only reasonable solution is to limit maximum height or better minimum width of column.
Attachment: Sample20872746201594327636_b402df1d.zip
|
<SfGrid @ref="Grid" DataSource="@GridData" ShowColumnChooser="true"
AllowPaging="true"
. . . >
. ..
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" AutoFit="true"></GridColumn>
<Template>
@((context as Order).Product)
</Template>
</GridColumn>
. ..
</GridColumns>
</SfGrid>
</div> |
Hi Rahul,
Of course I have tried to fix width of column already. But when I choose less columns and expand the width of browser screen, the grid looks ugly.
Please, ask the grid developer to update the grid to fulfil my request, as I wrote:
It is allowed to set MinWidth of column, but now it is used to mark limit of user changes of width only. Use this value to set minimum width of column when its content is wrapped. With this behavior, when MinWidth is set, for smaller screens such columns will not wrap to infinity, but will be limited. The whole grid will expand other view boundaries and will be scrolled.
Of course it should work with Templates.
|
[Index.razor]
<div style="height:calc(100vh - 90px)">
<SfGrid @ref="Grid" DataSource="@GridData" ShowColumnChooser="true"
AllowPaging="true"
. .. >
. ..
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" AutoFit="true"></GridColumn>
<GridColumn Field=@nameof(Order.Product) HeaderText="Product" CustomAttributes="@(new Dictionary<string, object>(){ { "class", "e-attr" }})">
<Template>
@((context as Order).Product)
</Template>
</GridColumn>
. ..
</GridColumns>
</SfGrid>
</div> |
|
[site.css]
@media screen and (max-width: 800px) {
.e-grid .e-attr {
width: 180px !important;
}
}
@media screen and (min-width: 800px) {
.e-grid .e-attr {
width: 280px !important;
}
} |
Thank you very much for this offer. I will try it within few days, after rewrite all project to NET6.
- 10 Replies
- 2 Participants
-
SG Stanislav Gordenko
- Nov 1, 2021 09:13 AM UTC
- Nov 12, 2021 03:49 AM UTC