Search code examples
devexpresscalculated-columnsdxgrid

DevExpress DxGrid. Join to values from DataSet in one column


I am loading data with a services using EntityFrameworkCore and showing data into a DxGrid. I need to combine, join or concatenate to items from my data in one column. I am working on a DevExpress Blazor Template.

This is the way I load my data. PublicacionesService is my services that it is inject on my .razor page and is declared in Program.cs

   IGrid Grid { get; set; }
   protected override async Task OnAfterRenderAsync(bool firstRender)
   {
    await Task.Delay(1000);
    GridData = await PublicacionesService.ViewPublicaciones.ToListAsync();
 
    PanelVisible = false;
    StateHasChanged();
  
   }

Then I have this component

   <DxGrid @ref="Grid"
     Data="GridData"
     EditMode="GridEditMode.EditRow"
     CssClass="mw-1100"
     CustomizeElement="Grid_CustomizeElement"
     @oncontextmenu:preventDefault
     EditModelSaving="Grid_EditModelSaving"
     DataItemDeleting="Grid_DataItemDeleting">

     <Columns>
     <DxGridDataColumn FieldName="Numero" Caption="Ver" Width="40px" />

     <DxGridDataColumn " Caption="Expediente"/> // What I expect ExpteNro / ExpteAnio

     <DxGridDataColumn FieldName="Objeto" DisplayFormat="D" Caption="Objeto" />
     <DxGridDataColumn FieldName="Descripcion" Caption="Descripcion" />
     <DxGridDataColumn FieldName="Fecha" Caption="Fecha" Width="140px" />
     </Columns>
    </DxGrid>

In a DxGridDataColumn I need to put both ExpteNro and ExpteAnio in a column. This is my class

   public partial class ViewPublicaciones
    {
      public long Id { get; set; }

      public int? ExpteNro { get; set; }

      public int? ExpteAnio { get; set; }

      public DateTime? FechaPres { get; set; }

    }

Solution

  • Ok. I took and easy way and I am not sure if it would make difference using another thing.

      public partial class ViewPublicaciones
    {
      public long Id { get; set; }
    
      public int? ExpteNro { get; set; }
    
      public int? ExpteAnio { get; set; }
    
      public DateTime? FechaPres { get; set; }
    
       public string ExpteNroAnio => $"{ExpteNro.ToString() } / 
       {ExpteAnio.ToString()} ";
    }
    
      <DxGridDataColumn FieldName="ExpteNroAnio" Caption="Expediente" 
       Width="120px" />
    

    If someone find something else be free to share. JIJIJI.