How to change the OData service URL simply in a common place while testing and production, that will impact the entire application and all Syncfusion components?

Answer:

We suggest you to achieve your requirement by defining the URL in a separate razor component and refer the same in all the Syncfusion components. In the below code snippet, Blazor Grid component is given as an example,

Index.razor, Counter.razor

<SfGrid TValue="Order" AllowPaging="true">

<SfDataManager Url=@RequiredUrl Adaptor="Adaptors.ODataV4Adaptor">SfDataManager>

<GridColumns>

<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120">GridColumn>

<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150">GridColumn>

<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130">GridColumn>

<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120">GridColumn>

GridColumns>

SfGrid>

@code{

public string RequiredUrl { get; set; }

protected override void OnInitialized()

{

RequiredUrl = BlazorApp3.Shared.URLComponent.CommonURL;

}

public class Order

{

public int? OrderID { get; set; }

public string CustomerID { get; set; }

public DateTime? OrderDate { get; set; }

public double? Freight { get; set; }

}

}


URLComponent.razor

[CascadingParameter]

public static string CommonURL { get; set; } = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders/";



Loader.
Up arrow icon