Computed Column Filter

Hello,
I have few computed columns in a datagrid. Filter on extended grid columns is giving exception where Due is a extended column. Kindly advise.

EXCEPTION

Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)

dotnet:    at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

dotnet: fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'WQIFSm5nz28QSYgVVgLK_ol75uLEjJ00Stru_clouhw'.
System.InvalidOperationException: The LINQ expression 'DbSet<TicketGroup>
    .Where(t => t.LocID == 1)
    .Where(t => t.Due == 2000)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|8_0(ShapedQueryExpression translated, <>c__DisplayClass8_0& )

You need ToList() for the data and filtering will be performed in-memory.

1 Like

Thanks! Its Working
image

Hi,
I have a related issue that computed column values are not calculated in the export methods.
Kindly advise.

Hi @Vinod_Pillai,

Only computed columns at database level can be exported. If you have some calculations in a template they cannot be exported.

Hi @enchev,
Thanks for your prompt response. I have added additional property using computed column by technique mentioned here .

The issue is the extended columns are exported but with zero values. How can we get the computed values in the exported excel.
Please guide me.

You need custom export method. You can add the data source export controller to the application ignore list and extend the relevant method with custom code that will populate the computed property:

1 Like

Steps To Write Custom Export methods using ExportController

  1. Extend the exportcontroller using partial class
         [HttpGet("/export/YourProject/YourURL/excel")]
        [HttpGet("/export/YourProject/YourURL/excel(fileName='{fileName}')")]
        public FileStreamResult ExportYourDataToExcel(string fileName = null)
        {
            var items = YourCustomMethod() // Should return AsQueryable();
            return ToExcel(queryview, fileName);
        }
  1. Extend your export page and add Custom Method to call above ExportURL [from step 1]
        public async Task ExportYourURLToExcel(Query query = null, string fileName = null,string select = "")
        {
            if (query != null && select != "")
            {
               query.Select = select;
            }
            UriHelper.NavigateTo(query != null ? query.ToUrl($"export/clique/YourURL/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/clique/YourURL/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true);
        }

Thanks for your valuable guidance