Skip to main content

DxGrid.GetColumns() Method

Returns a collection of all grid columns.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public IReadOnlyList<IGridColumn> GetColumns()

Returns

Type Description
IReadOnlyList<IGridColumn>

The column collection.

Remarks

Call the Grid’s GetVisibleColumns() method to get a collection of visible columns sorted based on their display order. To get a collection of all grid columns, call the GetColumns method. 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.

The GetDataColumns() method allows you to get a collection of bound and unbound data columns.

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);
    }
}

Blazor Grid Get Columns

Implements

See Also