Export to Excel does not take filters into account

Hi,

I have an MVC4 page with the Syncfusion Grid and some filters around the grid (ListBox). These filters work perfect when using a pager (I declared an OnBeginAction where I store all current filter values in args.data). 

But the default Export to Excel button is not able to do this. It can respond to a OnToolbarClickEvent. But this doesn't give me access to args.data. 

Is there a workaround for this?

2 Replies

SK Sarath Kumar P Syncfusion Team November 21, 2013 12:35 PM UTC

Hi Bas,

 

Thanks for using Syncfusion products.

 

We would like to let you know that in toolbar click event for excel check the condition  if (args._currentItemIndex == 0) then save the value in a variable and append the variable to the Excel form. In ExportToExcel action find the appended value in FormCollection  fc variable.

 

Please refer the below code snippets for your reference.

 

[controller.cs]

public ActionResult ExportToExcel(PagingParams args, FormCollection fc)  //find the value in  fc->base->All Keys.

 

{

var data = OrderRepository.GetAllRecords().Take(200).ToList();

return data.GridExportToExcel<MvcApplication627.Models.Student>("GridExcel.xlsx", ExcelVersion.Excel2007, args.ExportOption);

}

 

 

[view.cshtml]

 

<script type="text/javascript" language="javascript">

function ToolbarClick(sender, args) {

if (args._currentItemIndex == 0) {

var excel = "<input type='hidden' name='10000' id='excel'/>";

$("#GenericListGrid_exportExcel").append(excel);

}

}

 

</script>

 

Please refer our sample from the below link for your reference.

 

Link-Export.zip

 

Please let us know if you need further assistance.

 

Regards,

P.Sarathkumar.

 



FH Faizan Haider February 24, 2018 03:38 PM UTC

Yes

Loader.
Up arrow icon