Derivation of the TagHelper class

1 Answer 42 Views
Grid
Marcus
Top achievements
Rank 1
Marcus asked on 31 Oct 2024, 08:39 AM

We have a question regarding to the inheritance of TagHelpers.

Currently we want to derive some parts of the Telerik Grid as TagHelpers.
What we have done is to create our own instance of the TagHelper e.g. "ExampleGridTagHelper", inherit from your "GridTagHelper" class and override the "ProcessAsync" method.
There we set some properties that we want to have as default values (e.g. Name = "ExampleName").
Because of to the class Attributes [HtmlTargetElement] and [RestrictChildren], we have to derive each subpart of the grid (e.g. Columns, Scrollable, Sortable,...), which is not nice, but it works.

However when it comes to overriding the TagHelper GridColumnsTagHelper, we face a problem that we have not yet been able to solve.
Inside this TagHelper class there is a property Columns with the type IList<GridColumnTagHelper>.
When we want to add our derived version of GridColumnTagHelper to GridColumnsTagHelper.Columns, the framework cannot work with that.
Probably because in many cases the type of the TagHelper is stored inside a context.Items dictionary.
So in the end when we add <custom-column/> inside of <custom-columns></custom-columns> we get an error.

So our question here is: Is there a proper way to work around this or will this be changed in the "near" future?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Nov 2024, 12:04 PM

Hello Marcus,

 

Thank you for writing to us.

Due to maintenance issues in the long term and non-tested scenarios, we are not supporting custom components or classes, even when they are inherited directly from Telerik classes or taghelpers.

Instead, we highly recommend leveraging the PartialViews capability provided by ASP.NET Core MVC:
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-8.0

It allows the preemptive definition of custom configuration for the components like Grid which can then be used multiple times in the same project, just like a custom component.

I hope this clarification makes sense and I thank you for your understanding on this matter.

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Marcus
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or