@@ -53,7 +53,7 @@ The **JavaScript** tab in the following example implements a JS function and set
5353```` C#
5454@implements IDisposable
5555@inject IJSRuntime js
56-
56+
5757< TelerikGrid @ref = " @Grid"
5858 Data = " @GridData"
5959 Resizable = " true"
@@ -69,53 +69,56 @@ The **JavaScript** tab in the following example implements a JS function and set
6969 < GridColumn Field = @nameof (SampleData .LastName ) Title = " Last Name" Id = " NameColumn2" / >
7070 < / GridColumns >
7171< / TelerikGrid >
72-
72+
7373@code {
7474 [JSInvokable ]
7575 public async Task AutoFitAllColumns ()
7676 {
7777 await Grid .AutoFitAllColumnsAsync ();
78-
78+
7979 // from this point to the end of the method the logic is dedicated to
8080 // stretching the last grid column to the available horizontal space
8181 // this code also works even if there is no available horizontal space
82-
82+
8383 bool hasWhiteSpace = await js .InvokeAsync <bool >(" hasWhiteSpace" );
84-
84+
8585 if (hasWhiteSpace )
8686 {
8787 var state = Grid .GetState ();
88-
88+
8989 state .ColumnStates .LastOrDefault ().Width = " " ;
9090 state .TableWidth = null ;
91-
91+
9292 await Grid .SetStateAsync (state );
9393 }
9494 }
95-
95+
9696 protected override async Task OnAfterRenderAsync (bool firstRender )
9797 {
9898 if (firstRender )
9999 {
100100 IndexDotNetInstance = DotNetObjectReference .Create (this );
101-
101+
102102 await js .InvokeVoidAsync (" observeTarget" , IndexDotNetInstance , GridClass );
103103 }
104-
104+
105105 await base .OnAfterRenderAsync (firstRender );
106106 }
107-
107+
108108 private const string GridClass = " autofitter-columns" ;
109-
110- public TelerikGrid < SampleData > Grid { get ; set ; }
109+
110+ private TelerikGrid < SampleData > Grid { get ; set ; }
111+
112+ // Replace the Index type with the type of the component that hosts this code
111113 public DotNetObjectReference < Index > IndexDotNetInstance { get ; set ; }
112- public List < SampleData > GridData { get ; set ; }
113-
114+
115+ private List < SampleData > GridData { get ; set ; }
116+
114117 protected override void OnInitialized ()
115118 {
116119 GridData = GetData ();
117120 }
118-
121+
119122 public void Dispose ()
120123 {
121124 if (IndexDotNetInstance != null )
@@ -124,17 +127,17 @@ The **JavaScript** tab in the following example implements a JS function and set
124127 IndexDotNetInstance = null ;
125128 }
126129 }
127-
130+
128131 private List < SampleData > GetData ()
129132 {
130133 return Enumerable .Range (1 , 50 ).Select (x => new SampleData
131- {
132- Id = x ,
133- Name = $" name {x }" ,
134- LastName = $" Surname {x }"
135- }).ToList ();
134+ {
135+ Id = x ,
136+ Name = $" name {x }" ,
137+ LastName = $" Surname {x }"
138+ }).ToList ();
136139 }
137-
140+
138141 public class SampleData
139142 {
140143 public int Id { get ; set ; }
0 commit comments