Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(Grid): example code polish #2145

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions knowledge-base/grid-add-column-from-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ I want to add a custom Grid column programmatically. I would also like to define

## Solution

You can use the [`RenderTreeBuilder`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.rendering.rendertreebuilder?view=aspnetcore-6.0) class to create a GridColumn from the C# portion of the application.
You can use the [`RenderFragment Delegate`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.renderfragment?view=aspnetcore-8.0) to create a GridColumn from the C# portion of the application.
Tsvetomir-Hr marked this conversation as resolved.
Show resolved Hide resolved


>caption Add a GridColumn from code
Tsvetomir-Hr marked this conversation as resolved.
Show resolved Hide resolved

````CSHTML
@* Use the Render Tree Builder to add a grid column. Click on the Add a column button to see the result *@
@* Use the RenderFragment to add a grid column. Click on the Add a column button to see the result *@

<TelerikButton OnClick="@(() => CustomGridColumnFromCode = AddAGridColumn())">Add a column</TelerikButton>

Expand All @@ -58,15 +58,9 @@ You can use the [`RenderTreeBuilder`](https://docs.microsoft.com/en-us/dotnet/ap

private RenderFragment CustomGridColumnFromCode { get; set; }

private RenderFragment AddAGridColumn() => builder =>
private RenderFragment AddAGridColumn() => __builder =>
{
builder.OpenComponent(0, typeof(GridColumn));

builder.AddAttribute(0, "Field", "CustomDateField"); //The Field for the Column
builder.AddAttribute(1, "Title", "From code behind"); //The Title for the Column
builder.AddAttribute(2, "DisplayFormat", "{0:dd MMM yy}"); //The DisplayFormat for the Column

builder.CloseComponent();
<GridColumn Field="CustomDateField" Title="From code behind" DisplayFormat="{0:dd MMM yy}" />
};

public IEnumerable<SampleData> MyData = Enumerable.Range(1, 30).Select(x => new SampleData
Expand Down
Loading