Hi,
I’m working with a Kendo Grid using MVC4 with Razor’s syntax.
I need to be able to customize column’s order and displaying option in order to save user’s preference.
To achieve that, I tried to use a tab of GridColumnSettings and load it in the View using the LoadSettings method of the columns property.
I have a few issues with that:
- Even if the column order can be set dynamically with this method, I don’t understand how to use ClientTemplate or Template attribute of the GridColumnSettings object.
- By using this loading system I have two Gird's options who don’t work anymore: line and column are not selectable and the groupable option seems to not work too.
Thanks for your help.New to Kendo & MVC, so please bear with me.
I have a view that contains a grid that is working almost perfectly for me. My model is a System.Data.DataTable which is generated by a service, and is entirely dynamic (in that I don't know the schema until runtime). I'm injecting the model directly into the View, which uses the DataColumn definitions in the DataTable to generate the presentation layer (GridColumnSettings):
@using System.Data@using System.Linq@using Kendo.Mvc.UI@model System.Data.DataTable@(Html.Kendo() .Grid(Model) .Name("View") .Columns(columns => columns.LoadSettings( Model.Columns.Cast<DataColumn>().Select(dc => new GridColumnSettings { Member = dc.ColumnName, Title = dc.Caption, MemberType = dc.DataType, Format = "{0:" + dc.ExtendedProperties["format"] + "}", Width = "100px" }))) .Sortable() .Scrollable())
I'm quite happy with this approach - it's simple and elegant and keeps the Model (arguably ViewModel) and Controller blissfully ignorant of any Kendo/UI concepts. The only problem with this is that sorting always calls back into the Controller, and the DataTable is regenerated, even though it will not have changed.
I've seen in some Ajax samples the use of a 'serverSorting' property on a 'dataSource' instance, and I think I need to set that to false in order to get what I want, but I can't see how that applies in my MVC scenario. I don't want to set up a DataSource() that makes an Ajax() call that then Read()s the returned Json, because I have all the data already, but I'm struggling to see how else would I get access to the DataSource.ServerSorting property.
What am I missing?
.IncludeInMenu(false)