This is a migrated thread and some comments may be shown as answers.

Grid inherit/default parameters

4 Answers 969 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maurice
Top achievements
Rank 1
Maurice asked on 18 Feb 2021, 06:22 PM

Is it possible to create grid subcomponents which have a number of parameters set ?

Simple example (not realistic) would be to have components like

<SortableTelerikGrid>  which is just the <TelerikGrid Sortable="true">

so instead of having to specify all parameters in each page we can get some default parameters going.

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 19 Feb 2021, 12:14 PM

Hello Maurice,

Yes, it is possible. Just create a component in your app, put the Telerik Grid on it and set its parameters as desired. Then, add a few parameters to your own component that expose the settings you want changeable and point the grid parameters to them. It would probably be a generic component that takes the grid Data as a parameter too.

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tejinder
Top achievements
Rank 1
commented on 14 Dec 2021, 02:14 PM | edited

Comment removed.
0
Maurice
Top achievements
Rank 1
answered on 02 Mar 2021, 10:52 AM

Thanks, I managed to do this using only class as well, and that way I do not need to "proxy" all parameters.

My next problem is trying to create new gridcolumn types.

<TelerikGrid> 

   <GridColumns>

      <GridColumnBoolean>

 

Which should have a template to show 'deleted' or 'not deleted' for instance based on the column value. I have tried creating a .razor which contains a GridColumn but could not get it work.

 

Also tried a class inheriting from gridcolumn with an override on the builder tree.

 

What would you suggest would be the way to go ? This is a recurring thing for us. We want to have a certain template for all our boolean columns in all our grids so don't want to specify it everytime.

We also would like to minimize code in the .razor file itself.

0
Maurice
Top achievements
Rank 1
answered on 02 Mar 2021, 11:12 AM

I have managed to get it working. with fixed column name but I will fix that now

public class BooleanColumn : Telerik.Blazor.Components.GridColumn
    {
        public BooleanColumn()
        {
            this.FieldType = typeof(bool);
        }
        protected override void OnParametersSet()
        {
            base.OnParametersSet();
            this.Template = GetColumnTemplate("clt_deleted");
        }
 
      
        public RenderFragment<object> GetColumnTemplate(string propName)
        {
            RenderFragment<object> ColumnTemplate = context => __builder =>
            {
                Dictionary<string, object> rowdata = (Dictionary<string, object>)context;
                if ((bool)rowdata[propName])
                {
                    __builder.OpenElement(1, "div");
                    __builder.AddContent(2, "test");
                    __builder.CloseElement();
                }
                         
            };
 
            return ColumnTemplate;
        }
    }
0
Maurice
Top achievements
Rank 1
answered on 02 Mar 2021, 11:14 AM

simple

 this.Template = GetColumnTemplate(this.Field);

Tags
Grid
Asked by
Maurice
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Maurice
Top achievements
Rank 1
Share this question
or