gadeweever
gadeweever

Reputation: 123

Define Kendo UI default values and functions

We're using Kendo UI for a project and we have several grids in our application, among other widgets. We're in a situation where we want to define a list of properties all the grids should have.

For example, in Kendo MVC to mark a grid for keyboard support, you would add the Navigatable() property to it. For accessing the databind event you can do the following:

.Events(e => e.DataBound("onDataBound"))

So the questions:

  1. Is there a way to define a global navigatable somewhere so that all tables receive it?
  2. Is there a way to define an extra callback to be executed on all grids once they're done loading?

The scenario is that we want to post an update to the user whenever a grid is loaded, but we might want to do other things as well. If neither one nor two is possible, has anyone gone about this a different way?

Upvotes: 0

Views: 198

Answers (1)

Przemysław Kleszcz
Przemysław Kleszcz

Reputation: 646

You can easily wrap several functionalities by writing helper or extension. So you can place e.g Navigatable property in wrapper and start using your template instead of standard kendo grid configuration:

Helper:

@helper MyGridShortCut()
{
    Html.Kendo().Grid()
        .Name("Grid")
        .Columns(columns =>
        {

        }).Render();
}

@MyGridShortCut()

Extension:

public static Kendo.Mvc.UI.Fluent.GridBuilder<T> MyGrid<T>(this HtmlHelper helper, string name)
            where T : class
        {
            return helper.Kendo().Grid<T>()
                .Name(name)
                .Groupable()
                .Pageable()
                .Sortable()
                .Scrollable()
                .Filterable()
                .Pageable();
        }

You can also write custom grid by extending Kendo.Mvc.UI.Fluent.GridBuilder class. You can place your custom extra callbacks or properties there and they should be visible from fluent api in your views.

Upvotes: 1

Related Questions