.Columns having no effect when creating Kendo Grid through Custom HtmlHelper

0 Answers 66 Views
Grid
Richard
Top achievements
Rank 1
Richard asked on 08 Oct 2021, 07:59 PM | edited on 08 Oct 2021, 08:02 PM

I have the following code to create a Kendo Grid inside my custom HtmlHelper. The Ajax will return a 3 column data set to the DataSource (ID, Number, Name). No matter what I do, the Grid will return all the columns, and even if I try to change the title of the Number column to "Test Column" it has no effect. What am I missing? 


public static IHtmlContent FilterGrid<T>(this IHtmlHelper<T> html, string Name, string Controller) where T : class
        {
            HtmlContentBuilder htmlBuilder = new HtmlContentBuilder();

            htmlBuilder.AppendHtml(html.Kendo().DataSource<T>()
                .Name("ds_" + Name)
                .Ajax(dataSource => dataSource
                        .PageSize(20)
                        .Read(read => read.Action(Name + "_Read", Controller))
                    )
            );           

            htmlBuilder.AppendHtml(html.Kendo().Grid<T>()
                .Name("g_" + Name)
                .Pageable()
                .Sortable()
                .NoRecords()
                .DataSource("ds_" + Name)
                .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
                .Columns(c => {
                    c.Bound("Number").Title("Test title");
                    })
            ); 
            return htmlBuilder;
        }

Stephen
Top achievements
Rank 1
commented on 09 Oct 2021, 06:05 PM

Turns out it was caused by the persisting of the state of the grid in local storage. 

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Share this question
or