BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
protected override void OnAfterRender(bool isrender)
{
...
}
|
<EjsGrid @ref=@grid TValue="Order" AllowPaging="true" Width="100%" Height="100%">
...
</EjsGrid>
@code{
EjsGrid<Order> grid;
...
}
|
Hi there,
I'm wondering is there also a way to create dynamically columns to SFGrid?
I found out, this (maybe) the only way that is working, but there is always a compiler warning:
<SfGrid ID="Grid1" @ref="Grid" Columns="Cols" DataSource="Gdata" TValue="DataModel"></SfGrid>
@code {
public SfGrid<DataModel> Grid { get; set; }
public List<GridColumn> Cols = new List<GridColumn>();
public IEnumerable<DataModel> Gdata = new List<...>();
protected override async Task OnInitializedAsync()
{
Gdata = getData();
}
protected override void OnAfterRender(bool isRender)
{
Cols.Add(new GridColumn() { Field = "Field1", HeaderText = " Field1", Template="????"});
Cols.Add(new GridColumn() { Field = "Field2", HeaderText = " Field2 " });
Warning (active) BL0005 Component parameter 'Field' should not be set outside of its component.
Warning (active) BL0005 Component parameter 'HeaderText' should not be set...
}
private List<BewohnerModel> getData()...
Regards
S
Thanks Vignesh for your reply
it helps me a lot. The warning is gone and columns setting worked.
The setting of a template works also great in your example.
I tried to realise the template setting in my custom gridcolumn class, but it doesnt work here
public class gridcolumns<T>() where T : class,new()
{
props...
public static RenderFragment<object> DetailTemplate => (value) => { return b => { b.AddContent(0,"@<a rel='nofollow' href=\"@((value as "+typeof(T).Name+").DetailsLink)\" title=\"Details\"><i class=\"fal fa-info-circle fa-2x\"></i></a>");};};
Result: the content of that column is the correct html but as clear text
what did i wrong?
regards
Stefan
RenderFragment<object> DetailTemplate => (value) =>
{
return b =>
{
b.AddContent(0,@<a rel="nofollow" rel='nofollow' href='@(((value as DataModel).CustomerID + "DetailsLink"))' title="Details"><i class="fa fa-info-circle"></i></a>);
};
};
|
Hi Vignesh,
thanks for the reply, sorry now i can see my request wasnt clear enough. What i wanted to say is that your last example works perfectly in a code block of a razor component (.razor/.razor.cs), but not inside a standard class (.cs). And that's where i needed it. Just try your code example above in a basic class and you will see my issue.
Regards
Stefan
Hallo Vignesh,
thats aint necessary anymore, because the error was in my mind. :-)
I've understand now: RenderFragment is unable to recognize Blazor-Code outside a blazor file.
For example this code works perfect in *.razor:
RenderFragment<object> TemplateForDetailsLink => (value) => {return b =>
{
var data = value as DataModel;
var url = data.GetType().GetProperty(nameof("myUrlField")).GetValue(data, null).ToString();
b.AddContent(0,@<a rel='nofollow' rel='nofollow' href='@((url))' title="Details"><i class="fal fa-info-circle></i></a>);
};
};
but it doesnt in a c# class, even if i try to assign the code part as MarkupString there is no chance. So my Workaraound is now to set the code above in a component class and set the SFGrid.Gridcolumn.Template inside of it.
If you know a solution to set the above code in a classic c class, i'm all ears. otherwise consider it's done.
Regards
Stefan
HI vignesh, i'm always interested in perfect solutions. So my current solution isnt perfect. As i written before, if you have a solution in mind that would make it perfect, please share it. i would be very grateful. :-)
Regards
Stefan
Hi Vignesh,
i think were going to running around in circles now, so let us stop this at this point. Your suggestions were very helpful and i totaly can live with the razor code solution at least.
So thanks a lot for your time and your support.
Have a nice day
Stefan