blazor-devexpress-dot-blazor-dot-dxgrid-f7f6e3a2.md
Returns a collection of visible columns sorted based on their display order.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public IReadOnlyList<IGridColumn> GetVisibleColumns()
| Type | Description |
|---|---|
| IReadOnlyList<IGridColumn> |
The column collection.
|
The Grid layout can include multiple zones with columns. The display order of zones is as follows:
In a zone, the Grid displays columns based on their visible indexes in the following order:
Columns with non-negative visible indexes. The smaller the index, the more to the left the Grid displays the column.
Columns with unset and negative visible indexes. The display order of these columns corresponds to the column order in the grid markup.
Grouped columns are invisible unless you set the Grid’s ShowGroupedColumns property to true.
Call the Grid’s GetVisibleColumns method to get a collection of visible columns sorted based on their display order. Whenever these methods encounter a band, they include it followed by all its nested columns in the collection. If nested bands exist, the methods add them and their nested columns recursively.
To get a collection of all grid columns, call the GetColumns() method.
The following code snippet shows the difference between the results of the GetColumns and GetVisibleColumns methods.
@using Grid.Data
@inject WeatherForecastService ForecastService
<DxGrid Data="@Data" @ref="@MyGrid"
ShowFilterRow="true"
@bind-SelectedDataItems="@SelectedDataItems">
<Columns>
<DxGridSelectionColumn VisibleIndex="1"/>
<DxGridCommandColumn NewButtonVisible="false" EditButtonVisible="false"
DeleteButtonVisible="false" VisibleIndex="0" />
<DxGridDataColumn FieldName="TemperatureC" VisibleIndex="3" />
<DxGridDataColumn FieldName="TemperatureF" VisibleIndex="4" />
<DxGridDataColumn FieldName="Date" DisplayFormat="D" VisibleIndex="2" />
<DxGridDataColumn FieldName="Forecast" />
<DxGridDataColumn FieldName="CloudCover" />
</Columns>
</DxGrid>
<DxButton Click="@OnGetColumns">Get Columns</DxButton>
<DxButton Click="@OnGetVisibleColumns">Get Visible Columns</DxButton>
<p/>
<div><b>Columns</b>: @ColumnInfo</div>
<div><b>Visible Columns</b>: @VisibleColumnInfo</div>
@code {
IGrid MyGrid { get; set; }
object Data { get; set; }
string ColumnInfo { get; set; }
string VisibleColumnInfo { get; set; }
IReadOnlyList<object> SelectedDataItems { get; set; }
protected override void OnInitialized() {
Data = ForecastService.GetForecast();
}
void OnGetColumns() {
ColumnInfo = GetColumnInfo(MyGrid.GetColumns());
}
void OnGetVisibleColumns() {
VisibleColumnInfo = GetColumnInfo(MyGrid.GetVisibleColumns());
}
string GetColumnInfo(IEnumerable<IGridColumn> columns) {
var columnInfo = columns.Select((column, index) => (1 + index) + " - " + column switch
{
IGridDataColumn dataColumn => dataColumn.FieldName,
IGridSelectionColumn => "Selection Column",
IGridCommandColumn => "Command Column",
_ => null
});
return string.Join("; ", columnInfo);
}
}
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