Export to Excel with FilterValue

Hi Everyone,
New to C# and Radzen. Need some help in exporting the data grid view to Excel. I have a page where I called from another page passing a parameter associate id. then I used this id to filter my data view. Please see my FilterValue="associateId" below.

<RadzenDataGridColumn TItem="JAssociates.Models.jAssociate.AssociateFacility" Title="Associate Id" Property="AssociateId" FilterProperty="AssociateId" **
** FilterValue="associateId" Filterable="true">

This one works perfectly when I go to the page and also works when I do search and clearing the search. However, when I run the export to Excel or CSV, I always get ALL RECORDS including Associate ID not equal to the parameter that the page received.

Thank you for your help.

Hi,
Do refer to this section in online demo

    public void Export(string type)
    {
        service.Export("OrderDetails", type, new Query() 
            { 
                OrderBy = grid.Query.OrderBy, 
                Filter = grid.Query.Filter, 
                Select = string.Join(",", grid.ColumnsCollection.Where(c => c.GetVisible()).Select(c => c.Property)) 
            });
    }

as shown above you can use the query object to set filter values for export

I have setup as shown below:

        if (args == null || args.Value == "xlsx")
        {
            await jAssociateService.ExportAssociateFacilitiesToExcel(new Query

{
Filter = $@"{(string.IsNullOrEmpty(grid0.Query.Filter)? "true" : grid0.Query.Filter)}",
OrderBy = $"{grid0.Query.OrderBy}",
Expand = "Associate,LookupAssociateType,Facility,LookupJobDescription",
Select = string.Join(",", grid0.ColumnsCollection.Where(c => c.GetVisible()).Select(c => c.Property))
}, "AssociateFacilities");
}
}
However, my initial filter value on AssociateId is not being considered it seems. However, I am seeing it in the filter.

But when I click the Export to Excel, it gives me all the records from the table without filter.

image

I noticed though, If I manually enter a filter value, the Export works.

How can I maintain the initial filter?
Thanks.

You may setup the initial filter value as shown here

protected override Task OnAfterRenderAsync(bool firstRender)
    {
        if(firstRender)
        {
            var column = grid.ColumnsCollection.Where(c => c.Property == "FirstName").FirstOrDefault();

            if(column != null)
            {
                column.FilterValue = "Nan";
                column.FilterOperator = FilterOperator.StartsWith;
                grid.Reload();
            }
        }

        return base.OnAfterRenderAsync(firstRender);
    }

Thanks a lot. I think this will work too. I will try it also.
However, I have it, the same logic at the .razor file as shown below.

Then what I added in my cs when the Export is clicked, I reloaded the grid as shown below and it seems working.

protected async Task ExportClick(RadzenSplitButtonItem args)
{
await grid0.Reload();