Skip to content

Added the topic of How to set custom headers using a custom adaptor i… #3893

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

Open
wants to merge 2 commits into
base: hotfix/hotfix-v28.2.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public IActionResult Index()
{
return View();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@Html.EJS().Grid("CustomAdaptor").Columns(col =>
{
col.Field("CustomerID").HeaderText("Customer ID").Width("160").Add();
col.Field("Freight").HeaderText("Freight").Width("150").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipCity").HeaderText("Ship City").Width("150").Add();
col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add();

}).Created("created").Render()

<script>
function created(args) {
class CustomAdaptor extends ej.data.WebApiAdaptor {
beforeSend(args, xhr, settings) {
xhr.withCredentials = true;
super.beforeSend(args, xhr, settings);
xhr.headers.set('Syncfusion', true);
}
}
var grid = document.querySelector('#CustomAdaptor').ej2_instances[0];
grid.dataSource = new ej.data.DataManager({
url: "https://services.syncfusion.com/js/production/api/orders",
adaptor: new CustomAdaptor()
});
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<ejs-grid id="CustomAdaptor" created="created">
<e-grid-columns>
<e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" format="C2" width="120"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>

<script>
function created(args) {
class CustomAdaptor extends ej.data.WebApiAdaptor {
beforeSend(args, xhr, settings) {
xhr.withCredentials = true;
super.beforeSend(args, xhr, settings);
xhr.headers.set('Syncfusion', true);
}
}
var grid = document.querySelector('#CustomAdaptor').ej2_instances[0];
grid.dataSource = new ej.data.DataManager({
url: "https://services.syncfusion.com/js/production/api/orders",
adaptor: new CustomAdaptor()
});
}
</script>
18 changes: 17 additions & 1 deletion ej2-asp-core-mvc/grid/EJ2_ASP.MVC/data-binding/data-binding.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: post
title: Data Binding in ##Platform_Name## Grid Component
title: Data Binding in Syncfusion ##Platform_Name## Grid Component
description: Learn here all about Data Binding in Syncfusion ##Platform_Name## Grid component of Syncfusion Essential JS 2 and more.
platform: ej2-asp-core-mvc
control: Data Binding
Expand Down Expand Up @@ -114,6 +114,22 @@ public void ConfigureServices(IServiceCollection services)
});
}
```
## How to set custom headers using a custom adaptor in Syncfusion Grid

Custom headers allow you to send extra information along with your HTTP requests. This information can include authentication tokens, API keys, or any other data required by the server to process the request correctly. By adding custom headers, you can enhance the security and functionality of your application's data communication process.

This section explains how to integrate custom headers into Syncfusion Grid using the `beforeSend` method of the `WebApiAdaptor`.

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/grid/data-binding/custom-headers/razor %}
{% endhighlight %}
{% highlight c# tabtitle="custom-headers.cs" %}
{% include code-snippet/grid/data-binding/custom-headers/custom-headers.cs %}
{% endhighlight %}
{% endtabs %}

![Custom headers using custom adaptor](images/custom-headers.png)

## See Also

Expand Down
21 changes: 19 additions & 2 deletions ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/data-binding/data-binding.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: post
title: Data Binding in ##Platform_Name## Grid Control | Syncfusion
title: Data Binding in Syncfusion ##Platform_Name## Grid Control | Syncfusion
description: Learn here all about Data Binding in Syncfusion ##Platform_Name## Grid component of Syncfusion Essential JS 2 and more.
platform: ej2-asp-core-mvc
control: Data Binding
Expand Down Expand Up @@ -127,4 +127,21 @@ For this we need to install **Microsoft.AspNetCore.Mvc.NewtonsoftJson** package.
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
}
```
```

## How to set custom headers using a custom adaptor in Syncfusion Grid

Custom headers allow you to send extra information along with your HTTP requests. This information can include authentication tokens, API keys, or any other data required by the server to process the request correctly. By adding custom headers, you can enhance the security and functionality of your application's data communication process.

This section explains how to integrate custom headers into Syncfusion Grid using the `beforeSend` method of the `WebApiAdaptor`.

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/grid/data-binding/custom-headers/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="custom-headers.cs" %}
{% include code-snippet/grid/data-binding/custom-headers/custom-headers.cs %}
{% endhighlight %}
{% endtabs %}

![Custom headers using custom adaptor](images/custom-headers.png)
Binary file added ej2-asp-core-mvc/grid/images/custom-headers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.