Export data from grid

Hello

Is it possible to intercept the following before it is exported 

await this.TimeGrid.CsvExport(ExcelProperties)

The reason is that the above exports (in my case) hourly records from a grid.  It works beautifully becuase it exports all data on all the pages and even responds to any filters that the user has set on the grid. This is is exactly what I need.

I am now trying to export daily data, i.e. I want to rollup the hours so that only one record is exported per day.  If I use a custom datasource then I face the following problems

If I use the folowing as my custom datasource then this pulls all records, but it does not honour the filters that the user has in place:

var selectedTimes = await this.TimeGrid.GetCurrentViewRecordsAsync();

If I use the following then the filters are honoured, but it only returns 1 page of data if there are multiple pages:

var selectedTimes = this.TimeGrid.DataSource.ToList();

So the  await this.TimeGrid.CsvExport(ExcelProperties) ​is getting exactly the correct data,  I just need to mess with it (roll it up) before it exports.

Been trying to figure this out for ages.  Any ideas.

Thank you









1 Reply

MS Monisha Saravanan Syncfusion Team March 18, 2022 02:02 PM UTC

Hi Ditchford, 
  
Greetings from Syncfusion support. 
  
We have analyzed your query and we suggest you to use GetFilteredRecordsAsync Method instead of using GetCurrentViewRecordsAsync method. Kindly refer the below code snippet and attached sample for your reference. 
  
  
<SfGrid ID="Grid" @ref="DefaultGrid" DataSource="@Orders"  AllowFiltering="true" Toolbar="@(new List<string>() { "PdfExport" })" AllowPdfExport="true" AllowPaging="true"> 
   <GridPageSettings PageSize="4"></GridPageSettings> 
    <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
    private SfGrid<Order> DefaultGrid; 
    public List<Order> Orders { get; set; } 
  
    public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) 
    { 
        if (args.Item.Id == "Grid_pdfexport"//Id is combination of Grid's ID and itemname 
        { 
            PdfExportProperties PdfProperties = new PdfExportProperties(); 
            var data = await DefaultGrid.GetFilteredRecordsAsync(); 
            PdfProperties.DataSource = (List<Order>)data; 
            await this.DefaultGrid.PdfExport(PdfProperties); 
        } 
    } 
  
  
  
Kindly get back to us if you have further queries. 
  
Regards, 
Monisha 


Loader.
Up arrow icon