Back to Devexpress

DxGrid.GetColumnEditSettings<T>(String) Method

blazor-devexpress-dot-blazor-dot-dxgrid-dot-getcolumneditsettings-1-x28-system-dot-string-x29.md

latest6.5 KB
Original Source

DxGrid.GetColumnEditSettings<T>(String) Method

Returns editor settings of the column bound to the specified data source field.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public T GetColumnEditSettings<T>(
    string fieldName
)
    where T : class, IEditSettings

Parameters

NameTypeDescription
fieldNameString

A data source field name.

|

Type Parameters

NameDescription
T

An editor setting type.

|

Returns

TypeDescription
T

An object that contains editor settings.

|

Remarks

The Grid component generates and configures cell editors for columns based on associated data types. The component automatically displays column editors in the filter row and in data rows during edit operations. You can also place these editors in the edit or pop-up edit form.

The Grid allows you to access and customize editor settings at runtime. To get editor settings, pass a setting type and the corresponding data source field name to the GetColumnEditSettings method. The method returns null in the following cases:

  • The Grid does not have a column bound to the specified field
  • Editor settings of the column bound to the specified field are of a different type

Note

Editors, their settings, and types can change after you bind the Grid or its column to another data source. If the Grid is bound to an asynchronous data source, editor types can also change during Grid initialization.

The following code snippet enables an editor in the edit row for new rows only:

razor
@inject EmployeeService EmployeeData

<DxGrid Data="@employees" 
        EditMode="GridEditMode.EditRow" 
        EditStart="OnEditStart">
    <Columns>
        <DxGridCommandColumn />
        <DxGridDataColumn FieldName="FirstName" />
        <DxGridDataColumn FieldName="LastName" />
        <DxGridDataColumn FieldName="BirthDate" />
        <DxGridDataColumn FieldName="HireDate" />
        <DxGridDataColumn FieldName="Email" />
    </Columns>
</DxGrid>

@code {
    Employee[]? employees;
    protected override async Task OnInitializedAsync() {
        employees = await EmployeeData.GetData();
    }
    void OnEditStart(GridEditStartEventArgs e) {
        var settingsHireDate = e.Grid.GetColumnEditSettings<IDateEditSettings>("HireDate");
        if (settingsHireDate != null) {
          e.Grid.BeginUpdate();
          settingsHireDate.Enabled = e.IsNew;
          settingsHireDate.ShowDropDownButton = e.IsNew;
          e.Grid.EndUpdate();
        }
    }
}
csharp
using Microsoft.EntityFrameworkCore;
#nullable disable

namespace Grid.Northwind {
    public partial class NorthwindContext : DbContext {

        public NorthwindContext(DbContextOptions<NorthwindContext> options)
            : base(options) {
        }
        // ...
        public virtual DbSet<Employee> Employees { get; set; }
        // ...
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
            if(!optionsBuilder.IsConfigured) {
                optionsBuilder.UseSqlServer("Server=.\\sqlexpress;Database=Northwind;Integrated Security=true");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder) {
            modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
            // ...
            modelBuilder.Entity<Employee>(entity => {
                entity.HasIndex(e => e.EmployeeId, "EmployeeId");
                entity.HasIndex(e => e.LastName, "LastName");
                entity.HasIndex(e => e.FirstName, "FirstName");
                entity.HasIndex(e => e.Title, "Title");
                entity.HasIndex(e => e.BirthDate, "BirthDate");
                entity.HasIndex(e => e.HireDate, "HireDate");
                entity.HasIndex(e => e.Notes, "Notes");
            });
            // ...
            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
csharp
public partial class Employee {
        public int EmployeeId { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public string Title { get; set; }
        public string TitleOfCourtesy { get; set; }
        public Nullable BirthDate { get; set; }
        public Nullable HireDate { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string HomePhone { get; set; }
        public string Extension { get; set; }
        public byte[] Photo { get; set; }
        public string Notes { get; set; }
        public Nullable<int> ReportsTo { get; set; }
        public string PhotoPath { get; set; }
        public virtual ICollection<Order> Orders { get; set; }
        public string Text => $"{FirstName} {LastName} ({Title})";
        public string ImageFileName => $"Employees/{EmployeeId}.jpg";
    }

Handle the Grid’s CustomizeFilterRowEditor event to customize editors in the filter row. The CustomizeDataRowEditor event allows you to customize editors displayed in data rows, edit forms, or pop-up edit forms.

Implements

GetColumnEditSettings<T>(String)

See Also

DxGrid Class

DxGrid Members

DevExpress.Blazor Namespace