Skip to content

Documentation(940696)-Need to add Additional parameters to server whe… #3944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 14, 2025
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public IActionResult Index()
{
ViewBag.dataSource = OrderDetails.GetAllRecords();
return View();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div style="margin-left:180px">
<p style="color:red;" id="message"></p>
</div>
@Html.EJS().Grid("grid").DataSource((IEnumerable<object>)ViewBag.dataSource).AllowExcelExport().Toolbar(new List<string>
() { "ExcelExport" }).ToolbarClick("toolbarClick").ExcelExportComplete("excelExportComplete").Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer ID").Visible(false).Width("150").Add();
col.Field("ShipCity").HeaderText("Ship City").Width("150").Add();
col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();
}).Render()
</div>
<script>
function toolbarClick(args) {
var grid = document.getElementById("grid").ej2_instances[0];
if (args.item.id === "grid_excelexport") {
var queryClone = grid.query;
grid.query = new ej.data.Query().addParams("recordcount", "15");
document.getElementById("message").innerText = 'Key: ' + grid.query.params[0].key + ' and Value: ' + grid.query.params[0].value + ' on ' + args.item.text;
grid.excelExport();
}
}

function excelExportComplete(args) {
var grid = document.getElementById("grid").ej2_instances[0];
grid.query = new ej.data.Query();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div style="margin-left:180px">
<p style="color:red;" id="message"></p>
</div>
<ejs-grid id="grid" dataSource="@ViewBag.dataSource" allowExcelExport="true" toolbarClick="toolbarClick" excelExportComplete="excelExportComplete" toolbar="@(new List<string>() { "ExcelExport" })">
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" visible="false" width="150"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
<e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function toolbarClick(args) {
var grid = document.getElementById("grid").ej2_instances[0];
if (args.item.id === "grid_excelexport") {
var queryClone = grid.query;
grid.query = new ej.data.Query().addParams("recordcount", "15");
document.getElementById("message").innerText = 'Key: ' + grid.query.params[0].key + ' and Value: ' + grid.query.params[0].value + ' on ' + args.item.text;
grid.excelExport();
}
}

function excelExportComplete(args) {
var grid = document.getElementById("grid").ej2_instances[0];
grid.query = new ej.data.Query();
}
</script>
23 changes: 21 additions & 2 deletions ej2-asp-core-mvc/grid/EJ2_ASP.MVC/excel-export/excel-exporting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: post
title: Excel Exporting in ##Platform_Name## Grid Component
title: Excel Exporting in Syncfusion ##Platform_Name## Grid Component
description: Learn here all about Excel Exporting in Syncfusion ##Platform_Name## Grid component of Syncfusion Essential JS 2 and more.
platform: ej2-asp-core-mvc
control: Excel Exporting
Expand Down Expand Up @@ -253,6 +253,25 @@ In the following example, the [ToolbarClick](https://help.syncfusion.com/cr/aspn

![Add formula for the cell while exporting](../images/excel-exporting/excelexporting-formula.png)

## Passing additional parameters to the server when exporting

Passing additional parameters to the server when exporting data in the Syncfusion ASP.NET MVC Grid involves providing flexibility to include extra information or customize the export process based on specific requirements.

You can achieve this by utilizing the [Query](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_Query) property and the [ToolbarClick](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) event. Within the `Query` property, you can invoke the `addParams` method to add parameters to the request.

The following example demonstrates how to pass additional parameters to the server when Excel exporting within the `ToolbarClick` event. Within the event, the additional parameters, specifically **Recordcount** as **15**, are passed using the `addParams` method and displayed as a message.

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/grid/excel-export/additional-parameter/razor %}
{% endhighlight %}
{% highlight c# tabtitle="excel-export.cs" %}
{% include code-snippet/grid/excel-export/additional-parameter/excel-export.cs %}
{% endhighlight %}
{% endtabs %}

![Passing additional parameters to the server when exporting](../images/excel-exporting/additional-parameter.png)

## Limitations

* A CSV is a plain text format that does not support features such as cell rotation, font and color customization, column and row spanning, or adding formulas. CSV files store raw data without any formatting or styling.
Expand All @@ -261,4 +280,4 @@ In the following example, the [ToolbarClick](https://help.syncfusion.com/cr/aspn

* [Copy & paste excel](https://www.syncfusion.com/blogs/post/essential-js-2-copying-and-pasting-excel-sheet-data-to-grid-asp-net-mvc.aspx)

* [Copy and pasting excel sheet data to Grid](https://www.syncfusion.com/blogs/post/copy-and-pasting-excel-sheet-data-to-syncfusion-grid-for-mvc.aspx)
* [Copy and pasting excel sheet data to Grid](https://www.syncfusion.com/blogs/post/copy-and-pasting-excel-sheet-data-to-syncfusion-grid-for-mvc.aspx)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: post
title: Excel Exporting in ##Platform_Name## Grid Component
title: Excel Exporting in Syncfusion ##Platform_Name## Grid Component
description: Learn here all about Excel Exporting in Syncfusion ##Platform_Name## Grid component of Syncfusion Essential JS 2 and more.
platform: ej2-asp-core-mvc
control: Excel Exporting
Expand Down Expand Up @@ -253,6 +253,25 @@ In the following example, the [toolbarClick](https://help.syncfusion.com/cr/aspn

![Add formula for the cell while exporting](../images/excel-exporting/excelexporting-formula.png)

## Passing additional parameters to the server when exporting

Passing additional parameters to the server when exporting data in the Syncfusion ASP.NET Core Grid involves providing flexibility to include extra information or customize the export process based on specific requirements.

You can achieve this by utilizing the [query](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_Query) property and the [toolbarClick](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) event. Within the `query` property, you can invoke the `addParams` method to add parameters to the request.

The following example demonstrates how to pass additional parameters to the server when Excel exporting within the `toolbarClick` event. Within the event, the additional parameters, specifically **recordcount** as **15**, are passed using the `addParams` method and displayed as a message.

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/grid/excel-export/additional-parameter/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="excel-export.cs" %}
{% include code-snippet/grid/excel-export/additional-parameter/excel-export.cs %}
{% endhighlight %}
{% endtabs %}

![Passing additional parameters to the server when exporting](../images/excel-exporting/additional-parameter.png)

## Limitations

* A CSV is a plain text format that does not support features such as cell rotation, font and color customization, column and row spanning, or adding formulas. CSV files store raw data without any formatting or styling.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.