@@ -49,11 +49,13 @@ To autofit the Grid columns on the initial load of the component:
4949
5050The ** JavaScript** tab in the following example implements a JS function and sets up the ` MutationObserver ` tool to listen for DOM changes.
5151
52+ > Replace the ` Index ` type of the ` DotNetObjectReference ` with the type of the component that hosts this code.
53+
5254<div class =" skip-repl " ></div >
5355```` C#
5456@implements IDisposable
5557@inject IJSRuntime js
56-
58+
5759< TelerikGrid @ref = " @Grid"
5860 Data = " @GridData"
5961 Resizable = " true"
@@ -69,53 +71,56 @@ The **JavaScript** tab in the following example implements a JS function and set
6971 < GridColumn Field = @nameof (SampleData .LastName ) Title = " Last Name" Id = " NameColumn2" / >
7072 < / GridColumns >
7173< / TelerikGrid >
72-
74+
7375@code {
7476 [JSInvokable ]
7577 public async Task AutoFitAllColumns ()
7678 {
7779 await Grid .AutoFitAllColumnsAsync ();
78-
80+
7981 // from this point to the end of the method the logic is dedicated to
8082 // stretching the last grid column to the available horizontal space
8183 // this code also works even if there is no available horizontal space
82-
84+
8385 bool hasWhiteSpace = await js .InvokeAsync <bool >(" hasWhiteSpace" );
84-
86+
8587 if (hasWhiteSpace )
8688 {
8789 var state = Grid .GetState ();
88-
90+
8991 state .ColumnStates .LastOrDefault ().Width = " " ;
9092 state .TableWidth = null ;
91-
93+
9294 await Grid .SetStateAsync (state );
9395 }
9496 }
95-
97+
9698 protected override async Task OnAfterRenderAsync (bool firstRender )
9799 {
98100 if (firstRender )
99101 {
100102 IndexDotNetInstance = DotNetObjectReference .Create (this );
101-
103+
102104 await js .InvokeVoidAsync (" observeTarget" , IndexDotNetInstance , GridClass );
103105 }
104-
106+
105107 await base .OnAfterRenderAsync (firstRender );
106108 }
107-
109+
108110 private const string GridClass = " autofitter-columns" ;
109-
110- public TelerikGrid < SampleData > Grid { get ; set ; }
111+
112+ private TelerikGrid < SampleData > Grid { get ; set ; }
113+
114+ // Replace the Index type with the type of the component that hosts this code
111115 public DotNetObjectReference < Index > IndexDotNetInstance { get ; set ; }
112- public List < SampleData > GridData { get ; set ; }
113-
116+
117+ private List < SampleData > GridData { get ; set ; }
118+
114119 protected override void OnInitialized ()
115120 {
116121 GridData = GetData ();
117122 }
118-
123+
119124 public void Dispose ()
120125 {
121126 if (IndexDotNetInstance != null )
@@ -124,17 +129,17 @@ The **JavaScript** tab in the following example implements a JS function and set
124129 IndexDotNetInstance = null ;
125130 }
126131 }
127-
132+
128133 private List < SampleData > GetData ()
129134 {
130135 return Enumerable .Range (1 , 50 ).Select (x => new SampleData
131- {
132- Id = x ,
133- Name = $" name {x }" ,
134- LastName = $" Surname {x }"
135- }).ToList ();
136+ {
137+ Id = x ,
138+ Name = $" name {x }" ,
139+ LastName = $" Surname {x }"
140+ }).ToList ();
136141 }
137-
142+
138143 public class SampleData
139144 {
140145 public int Id { get ; set ; }
0 commit comments