Hello team,
I write you becuase I would like to understand why I have a datagrid:
With Data:
@iE_pmsMsNotificaciones1020
And this is working fine, but when I want to export the datagrid information, the exported file doesn´t content the filter previouly applied in the IEnumerable.
Any idea about what can be the problem?
The code that I´m using to export is:
if (args == null || args.Value == "xlsx")
{
await APTService.ExportPmsMsNotificaciones1020ToExcel(new Query
{
Filter = $@"{(string.IsNullOrEmpty(grid1020.Query.Filter) ? "true" : grid1020.Query.Filter)}",
OrderBy = $"{grid1020.Query.OrderBy}",
Expand = "CmsMsCentro,PmsMsOfSap,PmsMsPuesto,CmsMsUsuario,CmsMsUnidades",
Select = string.Join(",", grid1020.ColumnsCollection.Where(c => c.GetVisible() && !string.IsNullOrEmpty(c.Property)).Select(c => c.Property.Contains(".") ? c.Property + " as " + c.Property.Replace(".", "") : c.Property))
}, "PmsMsNotificaciones");
}
So, if the grid1020 doesn´t show information, on my understanding the excel file would have to be empty. But this is not working, because I have the excel file with all results of the table.
One more time, thanks for your support.
Regards.
enchev
October 8, 2024, 9:11am
2
The export code you have posted does not take into account any external filters - only the filters applied to DataGrid columns. You need to add the additional filters as well not just Query.Filter.
Thanks Enchev for your fast response.
I´ve tried:
public async Task ExportPmsMsNotificaciones1020_TEST_ToExcel(string dateFrom, string dateTo, Query query = null, string fileName = null)
{
navigationManager.NavigateTo(query != null ? query.ToUrl($"export/APT/pmsmsnotificaciones1020/TEST/excel(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/apt/pmsmsnotificaciones1020/TEST/excel(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true);
}
but i get the error "PAGE NOT FOUND"
[HttpGet("/export/APT/pmsmsnotificaciones1020/TEST/excel (dateFrom='{dateFrom}', dateTo='{dateTo}')")]
[HttpGet("/export/APT/pmsmsnotificaciones1020/TEST/excel (dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{fileName}')")]
public async Task ExportPmsMsNotificaciones1020ToExcelByDates(string dateFrom, string dateTo, string fileName = null)
{
//return ToExcel(ApplyQuery(await service.GetPmsMsNotificaciones1020(dateFrom, dateTo), Request.Query), fileName);
return ToExcel(ApplyQuery(await service.GetPmsMsNotificaciones1020(), Request.Query), fileName);
}
Any idea why?
Or do you have any idea about how I can do it? thanks again for your time Enchev.
@alberto.ramirez format your code - it is completely unreadable now. Check the forum FAQ for tips how to improve your post.
Also 404 errors mean that the requested URL is unrecognised. You may want to check why.
you are right Korche, sorry.
public async Task ExportPmsMsNotificaciones1020ToExcel(Query query = null, string fileName = null)
{
navigationManager.NavigateTo(query != null ? query.ToUrl($"export/apt/pmsmsnotificaciones1020/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/apt/pmsmsnotificaciones/excel(fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true);
}
but, I cannot access to:
[HttpGet("/export/APT/pmsmsnotificaciones1020/TEST/excel (dateFrom='{dateFrom}', dateTo='{dateTo}')")]
[HttpGet("/export/APT/pmsmsnotificaciones1020/TEST/excel (dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{fileName}')")]
public async Task<FileStreamResult> ExportPmsMsNotificaciones1020ToExcelByDates(string dateFrom, string dateTo, string fileName = null)
{
//return ToExcel(ApplyQuery(await service.GetPmsMsNotificaciones1020(dateFrom, dateTo), Request.Query), fileName);
return ToExcel(ApplyQuery(await service.GetPmsMsNotificaciones1020(), Request.Query), fileName);
}
because I get the error Page Not Found, so, I think that the problem comes in the service when I tray to navigate to the url. I think that the parameters that I´m trying to send are the reason of this error.
Maybe, you can see something on the code
There is some whitespace in the URL which doesn't look right - just before (dateFrom).
alberto.ramirez:
l
Thanks again Korchev, but same problem...
public async Task ExportPmsMsNotificaciones1020_TEST_ToExcel(string dateFrom, string dateTo, Query query = null, string fileName = null)
{
navigationManager.NavigateTo(query != null ? query.ToUrl($"export/APT/pmsmsnotificaciones1020/TEST/excel(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/APT/pmsmsnotificaciones1020/TEST/excel(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true);
}
[HttpGet("/export/APT/pmsmsnotificaciones1020/TEST/excel(dateFrom='{dateFrom}',dateTo='{dateTo}')")]
[HttpGet("/export/APT/pmsmsnotificaciones1020/TEST/excel(dateFrom='{dateFrom}',dateTo='{dateTo}',fileName='{fileName}')")]
public async Task<FileStreamResult> ExportPmsMsNotificaciones1020ToExcelByDates(string dateFrom, string dateTo, string fileName = null)
{
//return ToExcel(ApplyQuery(await service.GetPmsMsNotificaciones1020(dateFrom, dateTo), Request.Query), fileName);
return ToExcel(ApplyQuery(await service.GetPmsMsNotificaciones1020(), Request.Query), fileName);
}
I´m crazy with it because I don´t find the problem.
Don´t worry Korchev if you don´t find the issue, I appreciate your help too.
I would suggest to log the final URL and see if it is the expected one. If something doesn't satisfy the route you will end up with a 404 error.
1 Like
Thanks Korchev!!
I follow your suggestion and I found the issue... I was not using UrlEncoder.Default.Encode with some parameters and the url was not correct.
I fixed it and I could export the information correctly.
Thanks again.