Export custom object (not table/view) to excel

Using free Blazor edition. Trying to export custom list to Excel. Object Person doesn't exists in database.

Something like this.

In razor I've created a list

protected override void OnInitialized()

    List<Person> o = new List<Person>();
    Person p = new Person();
    p.ID = 1;
    p.LastName = "novak";
    p = new Person();
    p.ID = 2;
    p.LastName = "second";
    persons = o.ToList();


call Export in same razor file
public void Export(string type)
service.Export("Person", type, new Query() { OrderBy = grid.Query.OrderBy, Filter = grid.Query.Filter });

in services.cs

public void Export(string table, string type, Query query = null)
//public void Export(IEnumerable table, string type, Query query = null)
//navigationManager.NavigateTo(query != null ? query.ToUrl($"/export/{table}/{type}") : $"/export/{table}/{type}", true);

After calling I got error,
Sorry, but there's nothing here!
It looks like export expects Table, not object or data recived via WebApi.

Kindly advice

Indeed the Export functionality works only with database data sources. You can customize the generated code per your needs.

However I'd lik to see, how to export filtered data, from datagrid, not from database source, but custom object like mentioned above.
Tried to find some sample, but none found.
Kindly give me some pointers..

1 Like