Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(grid): Add KB for Grid min-width #1941

Merged
merged 26 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b0242b3
docs(grid)Add KB for Grid min-width
NansiYancheva Feb 19, 2024
793f73e
Fixing typos
NansiYancheva Feb 21, 2024
af7dc06
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Feb 22, 2024
6d011f2
start fixing recommendations
NansiYancheva Feb 26, 2024
2cfad89
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 1, 2024
b3545f9
fully changed content of the KB
NansiYancheva Mar 1, 2024
3b5e23c
fixed Columns
NansiYancheva Mar 1, 2024
6feb505
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
eca76cd
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
d3f0cf0
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
2432c4d
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
8cd3ecf
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
ce1e5e1
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
8c496fa
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
597f652
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
bfaf7de
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
ffc8819
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
076f85d
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
7d92a34
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
a27925b
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
eae0b49
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
6711ebc
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
cb4b8b7
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
6c6a5c3
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
c79bd1a
Update knowledge-base/grid-kb-specific-width.md
NansiYancheva Mar 7, 2024
b12037c
Rename grid-kb-specific-width.md to grid-horizontal-scrolling-no-colu…
NansiYancheva Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions knowledge-base/grid-horizontal-scrolling-no-column-widths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Horizontal Grid Scrolling without Column Widths
description: How to avoid shrinking or disappearing of Grid columns that have no column widths? How to get a horizontal scrollbar when the Grid columns have no widths?
type: how-to
page_title: How to Get Horizontal Scrollbar With no Grid Column Widths
slug: grid-kb-horizontal-scrolling-no-column-widths
position:
tags: telerik, blazor, grid, column, css
ticketid: 1588667, 1576220, 1615618
res_type: kb
---

## Environment

<table>
<tbody>
<tr>
<td>Product</td>
<td>Grid for Blazor, <br /> TreeList for Blazor</td>
</tr>
</tbody>
</table>


## Description

This knowledge base article gives solution to the following scenario:

* Some or none of the Grid columns have a `Width`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Some or none of the Grid columns have a `Width`.
* One or more of the Grid columns don't have `Width` defined.

* The columns without a `Width` shrink too much or disappear when the browser window or the Grid become narrow. This phenomenon occurs no matter if the Grid shows a horizontal scrollbar or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The columns without a `Width` shrink too much or disappear when the browser window or the Grid become narrow. This phenomenon occurs no matter if the Grid shows a horizontal scrollbar or not.
* The columns without `Width` shrink too much or disappear when the browser window or the Grid becomes narrow. This phenomenon occurs no matter if the Grid shows a horizontal scrollbar or not.



How to keep the above column `Width` configuration and:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
How to keep the above column `Width` configuration and:
* I want to keep the above column `Width` configuration and:
* I want the `Width`-less columns to remain visible and not shrink or disappear.
* I want the Grid to show a horizontal scrollbar.


* The width-less columns remain visible and do not shrink or disappear.
* The Grid shows a horizontal scrollbar.

## Solution

1. Use the Grid's [`Class` parameter]({%slug grid-overview%}#grid-parameters) to set a custom CSS class.
1. Set a `min-width` style for the Grid table elements through the custom CSS class. The `min-width` value must be greater than the sum of the all set column [`Width`s]({%slug grid-columns-width%}).

As a result, the width-less N number of columns will receive 1/N of the remaining space. A large-enough `min-width` value will ensure that the width-less columns remain visible and wide enough.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As a result, the width-less N number of columns will receive 1/N of the remaining space. A large-enough `min-width` value will ensure that the width-less columns remain visible and wide enough.
As a result, the `Width`-less N number of columns will receive 1/N of the remaining space. A large-enough `min-width` value will ensure that the `Width`-less columns remain visible and wide enough.


The Grid will show a horizontal scrollbar when its width is less than the table `min-width`.

````CSHTML
<TelerikGrid Data="@GridData"
Class="grid-min-width"
Height="400px">
<GridColumns>
<GridColumn Field="@nameof(Product.Name)" Title="Product Name" Width="200px" />
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:C2}" />
<GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:D}" />
</GridColumns>
</TelerikGrid>

<style>
.grid-min-width .k-table {
min-width: 600px;
}
/* optional - reset the min-width for detail Grids */
.grid-min-width .k-table .k-table {
min-width: auto;
}
</style>

@code {
private List<Product> GridData { get; set; } = new();

protected override void OnInitialized()
{
var rnd = new Random();

for (int i = 1; i <= 30; i++)
{
GridData.Add(new Product
{
Id = i,
Name = "Product name " + i,
Price = (decimal)(rnd.Next(1, 50) * 3.14),
Released = DateTime.Now.AddDays(-rnd.Next(1, 365)).AddYears(-rnd.Next(1, 10)),
});
}

base.OnInitialized();
}

public class Product
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
public DateTime Released { get; set; }
}
}
````

## See Also

* [Grid column width behavior]({%slug grid-columns-width%})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [Grid column width behavior]({%slug grid-columns-width%})
* [Grid Column Width Behavior]({%slug grid-columns-width%})

Loading