<SfGrid TValue="MyTable" AllowPaging="true" AllowSorting="true" AllowFiltering="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> <SfDataManager Url="odata/MyTable" CrossDomain="true" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> </SfGrid>
Thanks,Paul
|
[Startup.cs]
using System.IO;
using Microsoft.JSInterop;
namespace BlazorApp1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddScoped<HttpClient>(s =>
{
var ijs = s.GetService<IJSRuntime>();
var context = s.GetRequiredService<IHttpContextAccessor>();
var navManager = s.GetRequiredService<NavigationManager>();
Uri hostUri = null;
try
{
hostUri = new Uri(navManager.BaseUri);
}
catch (Exception)
{
. . .
}
var cookieContainer = new CookieContainer();
HttpClient client = HttpClientFactory.Create(new MessageHandler1(ijs)); //crate client instance by using this way
client.BaseAddress = hostUri;
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Accept-Encoding", "br, gzip, deflate");
if (context != null)
{
. . .
}
return client;
});
services.AddSyncfusionBlazor(false);
}
//add this Custom message handler
//add a new class MessageHandler
public class MessageHandler1 : DelegatingHandler
{
private int _count = 0;
private IJSRuntime ijs;
public MessageHandler1()
{
}
public MessageHandler1(IJSRuntime ijs)
{
this.ijs = ijs;
}
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
ijs.InvokeAsync<HttpRequestMessage>("handleError", request); //here we have send the request to js function and print the request in brower console
System.Threading.Interlocked.Increment(ref _count);
request.Headers.Add("X-Custom-Header", _count.ToString());
return base.SendAsync(request, cancellationToken);
}
}
. . .
}
}
|
|
[debug.js]
function handleError(request) {
console.log(request);
}
|