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

GridSettings in a Central Location

4 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon831
Top achievements
Rank 1
Simon831 asked on 13 Aug 2012, 03:03 PM
I would like to put the main Grid setup in a central location to be reused throughout the application.
What is the best way to do it?

eg something like:
@{
    var settings = new MySettings();   //containing .Pageable() .Sortable()  etc
    settings .Name("KendoGrid")
    settings .Columns(columns =>
    {
        columns.Bound(p => p.Description);
    })
 
           .Editable(editable => editable.Mode(GridEditMode.InLine))
        .ToolBar(commands => commands.Create())
    
    )
}
@Html.Kendo().Grid(settings).BindTo(Model).Render();

4 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 13 Aug 2012, 03:15 PM
Hi,

 You could create an html helper extension method:

public static class MyExtensions
{
        public static GridBuilder<T>  MyGrid<T>(this HtmlHelper html)
        {
             return html.Kendo().Grid<T>()
                                .Pageable()
                                .Sortable();
        }
}

then use it

@Html.MyGrid<T>().Name("MyGrid")

I hope this helps,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Simon831
Top achievements
Rank 1
answered on 14 Aug 2012, 08:55 AM
This is what I have, but I get a compiler error:
'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Kendo' and no extension method 'Kendo' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

Is there another using directive I am missing?

using System.Web.Mvc;
using Kendo.Mvc.UI.Fluent;
 
namespace MyProject.Web.Helpers
{
    public static class Helpers
    {
        public static GridBuilder<T> DefaultGrid<T>(this HtmlHelper html) where T : class
        {
            return html.Kendo().Grid<T>()
                               .Pageable()
                               .Sortable();
        }
    }
}
0
Atanas Korchev
Telerik team
answered on 14 Aug 2012, 10:24 AM
Hi,

 Yes, you are missing Kendo.Mvc.UI.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Steve
Top achievements
Rank 1
answered on 19 Sep 2012, 07:14 PM
Im confused.  Im getting the same error.  Yet there is no dll to add a reference to.  

You cant just stick this in the web.config if you dont actully have a dll to reference...right? 
         <add namespace="Kendo.Mvc.UI" />
Tags
Grid
Asked by
Simon831
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Simon831
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Share this question
or