@inherits ComponentBase @using Syncfusion.EJ2.Blazor.Data @using Syncfusion.EJ2.Blazor.DropDowns @using Syncfusion.EJ2.Blazor.Grids @using Syncfusion.EJ2.Blazor.Navigations @using Kairos.Models.OData @inject ApplicationState application @inject HttpClient httpClient @if (@configurations == null) { <div on="kairos.layout.showProgress()">Loading</div> } else { <div class="grid-odq" onload="kairos.layout.hideProgress()"> <div> <EjsToolbar ID=@("toolbar" + Identifier)> <ToolbarItems> <ToolbarItem Type="ItemType.Input" Align="ItemAlign.Left"> <template> <EjsDropDownList ID=@("odqName" + Identifier) @Ref=@ddlConfigurations Index="@index" DataSource="@configurations" OnValueSelect="@OnConfigurationValueSelect" Width="150px"> <DropDownListFieldSettings Text="Name" Value="Id" /> </EjsDropDownList> </template> </ToolbarItem> <ToolbarItem Type="ItemType.Separator" Align="ItemAlign.Left" /> </ToolbarItems> </EjsToolbar> </div> <div> <EjsGrid ID=@("grid" + Identifier) @Ref=@grid AllowPaging="true" Width="100%" Height="100%" Created="@OnGridCreated"> <GridPageSettings PageSize="5" /> </EjsGrid> </div> </div> } @functions { [Parameter] public string Identifier { get; set; } [Parameter] public string EntryPoint { get; set; } [Parameter] public string Location { get; set; } // UI Components EjsDropDownList ddlConfigurations; EjsGrid grid; string odqConfigurationsUrl; List<ODataConfigurationModel> configurations; int index = 1; protected override async Task OnParametersSetAsync() { await base.OnParametersSetAsync(); var restClient = new RestClient(httpClient); this.odqConfigurationsUrl = RestClient.RootUrl + "odata/configurations"; this.configurations = await restClient.GetAsync<List<ODataConfigurationModel>>("odata/configurations"); index = 0; } protected void OnConfigurationValueSelect(Syncfusion.EJ2.Blazor.DropDowns.SelectEventArgs args) { // Get New Index var idParts = args.Item.ID.Split('-'); var itemIndex = Convert.ToInt32(idParts[1]); this.BuildGridColumns(configurations[itemIndex]); } public void OnGridCreated(object args) { this.BuildGridColumns(configurations[index]); } void BuildGridColumns(ODataConfigurationModel configuration) { var columns = grid.Columns as List<GridColumn> ?? new List<GridColumn>(); columns.Clear(); foreach (var field in configuration.DisplayFields) { var column = new GridColumn { HeaderText = field.DisplayName, Field = field.DataName, Width = field.Width, Format = field.Format, Visible = field.Visible }; columns.Add(column); } grid.Columns = columns; grid.RefreshColumns(); BuildDataManager(configuration); } void BuildDataManager(ODataConfigurationModel configuration) { Console.WriteLine("BuildDataManager - URL : " + RestClient.RootUrl + "odata/configurations/" + Guid.Empty.ToString() + "/data"); var dataManager = new EjsDataManager(); dataManager.CrossDomain = true; dataManager.Adaptor = Adaptors.WebApiAdaptor; dataManager.EnableCaching = false; dataManager.Url = RestClient.RootUrl + "odata/configurations/" + Guid.Empty.ToString() + "/data"; dataManager.Offline = false; grid.DataSource = dataManager; grid.DataBind(); grid.Refresh(); } } |
Thanks in advance for your help.
Brice.
<EjsGrid @Ref=@grid AllowPaging="true" Width="100%" Height="100%">
<GridPageSettings PageSize="5" />
</EjsGrid>
@code{
EjsGrid grid;
protected override void OnAfterRender()
{
List<GridColumn> col = new List<GridColumn>();
col.Add(new GridColumn() { Field = "OrderID", HeaderText = "ID" });
col.Add(new GridColumn() { Field = "CustomerID", HeaderText = "Name" });
grid.Columns = col;
var dataManager = new EjsDataManager();
dataManager.CrossDomain = true;
dataManager.Adaptor = Adaptors.WebApiAdaptor;
dataManager.EnableCaching = false;
dataManager.Offline = false;
grid.DataSource = dataManager;
}
} |
<SfGrid TValue="ExpandoObject" @ref="@grid" Columns="@Cols" EnableAltRow="true" Width="500px" Height="250px">
<SfDataManager Adaptor="Adaptors.WebApiAdaptor" Url="/WeatherForecast" />
<GridEvents DataBound="Data" TValue="ExpandoObject"></GridEvents>
</SfGrid>
. . . . . ..
|
@if (showGrid || configuration != null)
{
<SfGrid TValue="ExpandoObject" @ref="@grid" Columns="@Cols" EnableAltRow="true" Width="500px" Height="250px">
<SfDataManager Adaptor="Adaptors.WebApiAdaptor" Url="/WeatherForecast" />
<GridEvents DataBound="Data" TValue="ExpandoObject"></GridEvents>
</SfGrid>
}
|