Skip to content

Commit 99863a3

Browse files
dimodiDimo Dimov
andauthored
Improve Grid and MediaQuery integration docs (#483)
Co-authored-by: Dimo Dimov <[email protected]>
1 parent aa54fa8 commit 99863a3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

components/mediaquery/integration.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ You can hide or more columns in the Grid based on the dimensions of the browser
2424

2525
>tip You can use similar approach for the Telerik TreeList in order to hide some of the component columns on small devices. You can even replace the entire components with other components that have a simpler layout and limited functionality, such as a ListView, for small devices.
2626
27+
>tip If you are [saving the Grid state]({%slug grid-state%}#save-and-load-grid-state-from-browser-localstorage), you need to remove column visibility information in `OnStateChanged`. Otherwise the saved column visibility may conflict with the visibility determined by the MediaQuery component.
28+
2729
````CSHTML
2830
@* Hide Grid columns on small screens - those below 1024px in this example *@
2931
3032
<TelerikMediaQuery Media="(max-width: 1023px)" OnChange="@( (doesMatch) => IsMediumDown = doesMatch )"></TelerikMediaQuery>
3133
3234
<TelerikGrid Data="@MyData"
33-
Pageable="true" PageSize="10">
35+
Pageable="true" PageSize="10"
36+
OnStateChanged="@( (GridStateEventArgs<User> args) => OnStateChangedHandler(args) )">
3437
<GridColumns>
3538
<GridCheckboxColumn Title="Select" Width="70px" />
3639
<GridColumn Field="@(nameof(User.Id))" Width="100px" />
@@ -60,6 +63,18 @@ You can hide or more columns in the Grid based on the dimensions of the browser
6063
@code {
6164
private bool IsMediumDown { get; set; } // sample rule to hide columns on small devices through their Visible parameter
6265
66+
async void OnStateChangedHandler(GridStateEventArgs<User> args)
67+
{
68+
// Strip column visibility information, so that only the MediaQuery component manages column visibility, not the Grid.
69+
// This code is needed only in MediaQuery integration scenarios.
70+
foreach (var columnState in args.GridState.ColumnStates)
71+
{
72+
columnState.Visible = null;
73+
}
74+
75+
//await LocalStorage.SetItem("local-storage-key", args.GridState);
76+
}
77+
6378
// only sample data for the grid follows
6479
public IEnumerable<User> MyData = Enumerable.Range(1, 30).Select(x => new User
6580
{

0 commit comments

Comments
 (0)