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

Grid extension method

6 Answers 554 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Robert Madrian asked on 08 Nov 2016, 02:45 PM

Hello,

I want to create a helper method that wraps a Kendo UI widget as described here:
http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-to-create-helper-methods-rendering-predefined-widgets-i-can-further-configure

using Kendo.Mvc.UI;
using Kendo.Mvc.UI.Fluent;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
 
namespace Gpdb.Helpers
 
{
    public static class HtmlHelperExtensions
 
    {
        public static GridBuilder<T> MyKendoGrid<T>(this HtmlHelper helper, string name)
            where T : class
        {
            return helper.Kendo().Grid<T>()
                .Name(name)
                .Groupable()
                .Pageable()
                .Sortable()
                .Scrollable()
                .Filterable()
                .Pageable();
        }
    }
}

but this doesn't work because of the following error (see attached Picture) - what I'm missing?

6 Answers, 1 is accepted

Sort by
0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 08 Nov 2016, 02:52 PM
public static GridBuilder<T> MyKendoGrid<T>(this HtmlHelper<T> helper, string name)
            where T : class
        {
            return helper.Kendo().Grid<T>()            
                .Name(name)
                .Groupable()
                .Pageable()
                .Sortable()
                .Scrollable()
                .Filterable()
                .Pageable();
        }

found the solution:

 

0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 08 Nov 2016, 02:52 PM

found the error:

 

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

0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 08 Nov 2016, 03:39 PM

Sorry not the solution - now I have the Problem in the Razor View (see Picture)

robert

 

0
Danail Vasilev
Telerik team
answered on 10 Nov 2016, 11:39 AM
Hi Robert ,

You can use the GridBuilder type instead of  HtmlHelper. For example:

C#:
public static GridBuilder<T> MyKendoGrid<T>(this GridBuilder<T> helper, string name)
    where T : class
{
    return helper
        .Name(name)
        .Groupable()
        .Pageable()
        .Sortable()
        .Scrollable()
        .Filterable()
        .Pageable();
}

cshtml:

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
        .MyKendoGrid("myGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.OrderID).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false))).Width(225);
            columns.Bound(p => p.ShipName).Width(500).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
        })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .ServerOperation(true)
        .Read(read => read.Action("Orders_Read", "Grid"))
     ))


Regards,
Danail Vasilev
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 10 Nov 2016, 12:12 PM

Hi Danail,

if I use your approach I cannot use JQuery to access the Grid like that: $("#grid").data("kendoGrid").dataSource.page(1); it will not found...

another solution might be to use IHtmlHelper<dynamic> so I can use @(Html.MyKendoGrid...

public static GridBuilder<TModel> MyKendoGrid<TModel>(this IHtmlHelper<dynamic> helper)
            where TModel : class
0
Accepted
Danail Vasilev
Telerik team
answered on 11 Nov 2016, 07:42 AM
Hi Robert,

I am glad you have managed to find a solution. 

Let us know if you need any assistance with our products.

Regards,
Danail Vasilev
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
Grid
Asked by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Answers by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Danail Vasilev
Telerik team
Share this question
or