blazor-devexpress-dot-blazor-56a6c8b0.md
An interface that defines a Grid column’s API members (properties and methods).
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public interface IGridColumn
The following members return IGridColumn objects:
We recommend that you use the IGridColumn interface when you access a Grid column’s API members in any of the following cases:
@ref attribute to reference a Grid column. For example, you set or change values of the Grid column’s parameters outside the markup.Column object from templates or event handlers.In all other cases, bind your data to column parameters.
The following code snippet uses the RowClick event to handle clicks on grid rows. The event’s Column argument (which returns an IGridColumn object) provides access to a grid column against which data rows are grouped.
@inject WeatherForecastService ForecastService
<DxGrid Data="@Data"
RowClick="OnRowClick"
AllowGroup="true"
ShowGroupPanel="true">
<Columns>
<DxGridDataColumn FieldName="Date" Caption="Date" />
<DxGridDataColumn FieldName="TemperatureC" Caption="@("Temp. (\x2103)")" Width="120px" GroupIndex="0"/>
<DxGridDataColumn FieldName="TemperatureF" Caption="@("Temp. (\x2109)")" Width="120px" />
<DxGridDataColumn FieldName="Forecast" Caption="Forecast" />
<DxGridDataColumn FieldName="CloudCover" Caption="CloudCover" GroupIndex="1"/>
</Columns>
</DxGrid>
@Alert
@code {
public string Alert { get; set; } = "";
object Data { get; set; }
protected override void OnInitialized() {
Data = ForecastService.GetForecast();
}
void OnRowClick(GridRowClickEventArgs e) {
Alert = $"Data rows are grouped by the {e.Column.Caption} column. ";
}
}
using System;
public class WeatherForecast {
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public double TemperatureF => Math.Round((TemperatureC * 1.8 + 32), 2);
public string Forecast { get; set; }
public string CloudCover { get; set; }
public bool Precipitation { get; set; }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
public class WeatherForecastService {
private List<WeatherForecast> Forecast { get; set; }
private static string[] CloudCover = new[] {
"Sunny", "Partly cloudy", "Cloudy", "Storm"
};
Tuple<int, string>[] ConditionsForForecast = new Tuple<int, string>[] {
Tuple.Create( 22 , "Hot"),
Tuple.Create( 13 , "Warm"),
Tuple.Create( 0 , "Cold"),
Tuple.Create( -10 , "Freezing")
};
public WeatherForecastService() {
Forecast = CreateForecast();
}
private List<WeatherForecast> CreateForecast() {
var rng = new Random();
DateTime startDate = DateTime.Now;
return Enumerable.Range(1, 15).Select(index => {
var temperatureC = rng.Next(-10, 30);
return new WeatherForecast {
Date = startDate.AddDays(index),
TemperatureC = temperatureC,
CloudCover = CloudCover[rng.Next(0, 4)],
Precipitation = Convert.ToBoolean(rng.Next(0, 2)),
Forecast = ConditionsForForecast.First(c => c.Item1 <= temperatureC).Item2
};
}).ToList();
}
public IEnumerable<WeatherForecast> GetForecast() {
return Forecast.ToArray();
}
// ...
}
// ...
builder.Services.AddSingleton<WeatherForecastService>();
See Also