@using System.Linq.Dynamic.Core
@inject IHttpService httpService
@using PanoptesFrontend.Services
@foreach(var column in columns)
{
@context[@column.Key]
}
@code {
IList> selectedItems;
[Parameter]
public List> data { get; set; }
[Parameter]
public int TableId {get; set;}
public IDictionary columns { get; set; }
public string GetColumnPropertyExpression(string name, Type type)
{
var expression = $@"it[""{name}""].ToString()";
if (type == typeof(int))
{
return $"int.Parse({expression})";
}
else if (type == typeof(DateTime))
{
return $"DateTime.Parse({expression})";
}
return expression;
}
protected override async Task OnInitializedAsync()
{
// Generate the columns dynamically based on the properties of the first object in the list
var firstItem = data.FirstOrDefault();
if (firstItem != null)
{
columns = firstItem.ToDictionary(p => p.Key, p => p.Value.GetType());
foreach (var column in columns.ToList())
{
if (column.Value != typeof(int) && column.Value != typeof(DateTime))
{
columns[column.Key] = typeof(string);
}
}
}
}
private async Task Update()
{
string module = "localhost:8080";
var response = await httpService.GetAsync($"http://localhost:10000/{module}/{TableId}");
if (response.Data != null)
{
data.Clear();
data.AddRange(response.Data);
}
await InvokeAsync(() => StateHasChanged());
}
}