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

[Solved] Customize Default Behaviors of Telerik Controls

2 Answers 97 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jeff
Top achievements
Rank 1
Jeff asked on 27 Oct 2011, 05:18 PM
Hi - Is there a way to customize the default behaviors of the Telerik controls (on app startup, or via some sort of configuration)?  

I'd like to set application-wide defaults for control features/behaviors, such as disabling spinners on a CurrencyTextBox, or setting the filter style on a ComboBox, to promote consistency throughout the application.   I realize we can adjust them on each control, but it would be great if we could adjust the default options (almost like a template or style), then only override them if/when necessary.

Thanks,

Jeff

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Tunev
Telerik team
answered on 28 Oct 2011, 03:42 PM
Hi Jeff,

 There is no built-in support, but you can easily achieve that by using a custom extension method for the HtmlHelper class. For convenience I prepared a small sample that shows how to configure the Grid component. The same logic can be used with all other components.

Here are the steps:

1. Create the custom extension and set the common properties there:

namespace GridHtmlHelper.Models
{
    public static class GridHtmlHelperExtensions
    {
        public static GridBuilder<T> Grid<T>(this HtmlHelper html, IEnumerable<T> model)
            where T : class
        {
            var builder = html.Telerik().Grid(model);
 
            builder.Pageable();
            builder.Sortable();
            builder.Selectable();
            builder.Filterable();
 
            return builder;
        }
 
    }
}

2. Add its namespace in the web.config file as well, so it can be recognized by the framework:

<add namespace="GridHtmlHelper.Models" />

3. Use modified @{Html.Grid() in your views
e.g
@{ Html.Grid(Model)
        .Name("OrdersGrid")
        .DataKeys(keys => keys.Add("ID"))
        .Columns(columns =>
        {
            columns.Bound(o => o.ID);
            columns.Bound(o => o.Name);
 
        })
         
        .Render();
}


This way you can also override the pre-set properties - just set them to a new value in the grid's declaration.


Greetings,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Jeff
Top achievements
Rank 1
answered on 28 Oct 2011, 04:04 PM
Thanks Georgi!  That'll do exactly what we want.  Thanks for the detailed example / solution as well.  

Jeff
Tags
General Discussions
Asked by
Jeff
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or