Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IGrid Interface

An interface that defines the DxGrid component’s API members (properties and methods).

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public interface IGrid

#Remarks

We recommend that you use the IGrid interface when you access Grid API members in any of the following cases:

  • You use the @ref attribute to reference a Grid object. For example, you set or change values of the Grid parameters outside the component’s markup.
  • You access a Grid object from templates or event handlers.

In all other cases, bind your data to Grid parameters.

The following code snippet changes multiple sort options in the Grid. Note that when you change a Grid parameter that causes the Grid to update or you need to prevent excessive component redraw operations, enclose your code between the BeginUpdate() and EndUpdate() method calls.

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxGrid Data="@Data" @ref="MyGrid">
    <Columns>
        <DxGridDataColumn FieldName="Country" SortIndex="0" />
        <DxGridDataColumn FieldName="City" SortIndex="1" />
        <DxGridDataColumn FieldName="OrderDate" />
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" />
        <DxGridDataColumn FieldName="Quantity" />
    </Columns>
</DxGrid>
<br />

<DxButton Click="@(() => ChangeSortInfo())">Change Sort Options</DxButton>

@code {
    object Data { get; set; }
    NorthwindContext Northwind { get; set; }
    IGrid MyGrid { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        Data = Northwind.Invoices
            .ToList();
    }

    void ChangeSortInfo() {
        MyGrid.BeginUpdate();
        MyGrid.ClearSort();
        MyGrid.SortBy("OrderDate");
        MyGrid.SortBy("UnitPrice", GridColumnSortOrder.Descending);
        MyGrid.EndUpdate();
    }

    public void Dispose() {
        Northwind?.Dispose();
    }
}

See Also