Null Reference Exception on Excel Export with Aggregation Columns

Hello,

Requirements are to export all data within the grid regardless of the filter applied to it, along with a sum aggregate, to excel. However, I am getting a null reference exception on exporting. Confirm that this behavior occurs in 19+ versions.

Have attached an example.  Don't know if this is something I am doing wrong? a bug? not too sure, but would appreciate the help in achieving this requirement.

Much Thanks


Attachment: DataGrid_Server_4de848b1.zip

5 Replies

MS Monisha Saravanan Syncfusion Team September 19, 2022 02:55 PM UTC

Hi Shannon,


Greetings from Syncfusion support.


We have analyzed your query and modified your sample as per your shared requirement. Kindly check the attached sample for your reference.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGrid_Server1333181011.zip


Also we would like to inform that the aggregates will be exported with description unless we customize the values inside Excel. We can get only the default values by passing the values from the event args without any customization. Kindly refer the below code snippet and sample for your reference.


public void ExcelAggregateTemplateInfoHandler(ExcelAggregateEventArgs args)

    {

        if (args.Column.Field == "Freight")

        {

            args.Cell.Value = args.Value;       //customize the aggregate cell value here

        }

        // Here you can customize your code

    }

   

 

    }


Kindly get back to us if you need further assistance.



Regards,

Monisha




SH Shannon September 20, 2022 04:07 PM UTC

Hi,


Thanks for helping out. But that example doesn't  really help. Sorry for any confusion. I need the ability to always export all columns and all data regardless of searching or columns hidden on the grid. So far example:


The user searches for "1001" and hides column: Order Date




Should still be able to export all data, with all columns as below:




MS Monisha Saravanan Syncfusion Team September 21, 2022 03:54 PM UTC

Hi Shannon,


Thanks for the update.


Query: “I need the ability to always export all columns and all data regardless of searching or columns hidden on the grid.”


We have checked your query and we suspect that you need to export hidden columns and all the columns. In DataGrid we have support to export all the datas by using DataSource property. Also we have support to export hidden columns by enabling the IncludeHiddenColumn property as true. Kindly check the attached code snippet and sample for your reference.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGrid_Server-520138607.zip



if (args.Item.Id == "Grid_excelexport") //Id is combination of Grid's ID and itemname

        {

            ExcelExportProperties ExcelProperties = new ExcelExportProperties();

            ExcelProperties.DataSource = Orders;

            ExcelProperties.IncludeHiddenColumn = true;

            await this.DefaultGrid.ExcelExport(ExcelProperties);

        }


Reference: https://blazor.syncfusion.com/documentation/datagrid/excel-exporting#custom-data-source

https://blazor.syncfusion.com/documentation/datagrid/excel-exporting#export-hidden-columns


Please let us know if you have any concerns.


Regards,

Monisha



SH Shannon September 21, 2022 04:20 PM UTC

Hi Monisha,


For some reason your example is not like the sample I shared earlier. I've revised your sample to include column chooser within the toolbar along with a column aggregate - as this is part of the requirement.  


Still getting the null reference exception when exporting to excel. The aggregate column also needs to be included within export, and all columns even if they are hidden, and all data .  Many thanks again for the help!


Attachment: DataGrid_Server520138607_6116992c.zip


MS Monisha Saravanan Syncfusion Team September 22, 2022 03:06 PM UTC

Hi Shannon,


Sorry for the inconvenience.


Query: “Still getting the null reference exception when exporting to excel. The aggregate column also needs to be included within export, and all columns even if they are hidden, and all data . ”


We have checked your shared sample and we could able to reproduce the reported issue when clicking export button in the toolbar. We would like to inform that in your shared sample you have used version (19.3.x). We have resolved the reported issue at our end. So please upgrade to our latest version (20.2.0.50) and check whether the reported issue persist at your end.


Also we would like to inform that if DataGrid contains aggregate columns then the data contained in the Grid will be exported rather then using datasource assigned in the DataSource property. This is the default behaviour of the Grid. Because for an example if an Grid contains 75 rows and after performing search if there is only 1 rows then the aggregate will be calculated for the 1 row only. Now if we export the Grid by using customized DataSource it will contain 75 records but the aggregate value will be incorrect. So if an aggregate column is present then by default it will export the datas present in the UI.


Please let us know if you have any concerns.


Regards,

Monisha


Loader.
Up arrow icon