or
@(Html.Kendo().Grid<MesFormations.Models.EmployeGridView>() .Name("grid") .Columns(columns => { columns.Bound(e => e.NomEmploye).Width(110); columns.Bound(e => e.CourrielEmploye).Width(110); columns.Bound(e => e.Telephone).Width(110); columns.Bound(e => e.PosteTelephone); }) .Sortable() .Pageable() .Scrollable() .ClientDetailTemplateId("template") .HtmlAttributes(new { style = "height:430px;" }) .DataSource(dataSource => dataSource .Ajax() .PageSize(6) .Read(read => read.Action("HierarchyBinding_Employees", "Employe")) ) .Events(events => events.DataBound("dataBound")))<script id="template" type="text/kendo-tmpl"> @(Html.Kendo().Grid<MesFormations.Models.FormationEmployeGridView>() .Name("grid_#=NoEmploye#") .Columns(columns => { columns.Bound(o => o.NoFormation).Width(70); columns.Bound(o => o.DateFormation).Width(110); columns.Bound(o => o.DateModification); columns.Bound(o => o.Remarques).Width(200); }) .DataSource(dataSource => dataSource .Ajax() .PageSize(5) .Read(read => read.Action("HierarchyBinding_Orders", "Employe", new { employeeID = "#=NoEmploye#" })) ) .Pageable() .Sortable() .ToClientTemplate() )</script><script> function dataBound() { this.expandRow(this.tbody.find("tr.k-master-row").first()); }</script>public ActionResult HierarchyBinding_Employees([DataSourceRequest] DataSourceRequest request) { return Json(GetEmployees().ToDataSourceResult(request)); } public ActionResult HierarchyBinding_Orders(int employeeID, [DataSourceRequest] DataSourceRequest request) { return Json(GetOrders() .Where(order => order.NoEmploye == employeeID) .ToDataSourceResult(request)); } private static IEnumerable<FormationEmployeGridView> GetOrders() { var northwind = new FormationContext(); //var loadOptions = new DataLoadOptions(); //loadOptions.LoadWith<Order>(o => o.Customer); //northwind.LoadOptions = loadOptions; return northwind.FormationEmploye.Select(order => new FormationEmployeGridView { NoFormationEmploye = order.NoFormationEmploye, NoEmploye = order.NoEmploye, NoFormation = order.NoFormation, DateFormation = order.DateFormation, Remarques = order.Remarques, DateModification = order.DateModification }); } private static IEnumerable<EmployeGridView> GetEmployees() { var northwind = new FormationContext(); return northwind.Employes.Select(employee => new EmployeGridView { NoEmploye = employee.NoEmploye, PrenomEmploye = employee.PrenomEmploye, NomEmploye = employee.NomEmploye, CourrielEmploye = employee.CourrielEmploye, Telephone = employee.Telephone, PosteTelephone = employee.PosteTelephone }); }<httpRuntime targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /><link rel="stylesheet" href="https://da7xgjtj801h2.cloudfront.net/2013.1.514//styles/kendo.common.min.css"> <link rel="stylesheet" href="https://da7xgjtj801h2.cloudfront.net/2013.1.514/styles/kendo.default.min.css"> @Styles.Render("~/Content/all") <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> @Scripts.Render("~/bundles/all") <script src="https://da7xgjtj801h2.cloudfront.net/2013.1.514/js/kendo.web.min.js"></script> <script src="https://da7xgjtj801h2.cloudfront.net/2013.1.514/js/kendo.aspnetmvc.min.js"></script>@(Html.Kendo().Grid<ZZ.Model.ProductModel>() .Name("products-grid") .Columns(columns => { columns.Bound(o => o.id).ClientTemplate("<input type='checkbox' data-id='#: id #'/>").Title(" ").Sortable(false).Width(22).Filterable(false); columns.Bound(o => o.name).Title("Name").Width(140); columns.Bound(o => o.handle).Title("Handle").Width(140); columns.Bound(o => o.type).Title("Type").Width(140); columns.Bound(o => o.sku).Title("SKU").Width(80); }) .Scrollable() .Resizable(r=>r.Columns(true)) .Sortable() .Filterable() .Pageable(p=>p.Messages(m=>m.Display("{0}-{1} of {2} products"))) .HtmlAttributes(new { style = "height: 600px" }) .DataSource(dataSource => dataSource .Ajax() .PageSize(250) .Read(read => read.Action("GetProducts", "Products")) ) // .Events(events => events.Change("select")) )public JsonResult GetProducts([DataSourceRequest] DataSourceRequest request) { var businessId = BusinessInfo.Id; var result = _repository.GetProductsInDatabase(businessId).OrderBy(o=>o.handle).ToDataSourceResult(request); return Json(result, JsonRequestBehavior.AllowGet); } <script src="https://da7xgjtj801h2.cloudfront.net/2013.1.514/js/kendo.aspnetmvc.min.js"></script>
<script src="https://da7xgjtj801h2.cloudfront.net/2013.1.514/js/kendo.web.min.js"></script>
Hi,
this issue is a followup on this thread!
I am trying to extend the example to persist column state in a cookie. Users can hide/show/resize columns. I thought I could use the same method described in the thread above. Here is my code:
// Add handlers to show and hide events .Events(events => events.ColumnHide("onColumnHideIOrShow")) .Events(events => events.ColumnShow("onColumnHideIOrShow"))
// Function is called when a column is hidden or Shown function onColumnHideIOrShow(e) { var columnlistCookieName = "GridMarColumns"; var grid = $("#GridMar").data("kendoGrid"); var columns = grid.columns; var serializedColumns = kendo.stringify(columns); $.cookie(columnlistCookieName, serializedColumns); }
// On load recreate the column list as found in the cookie $(document).ready(function () { var columnlistCookieName = "GridMarColumns"; var serializedColumns = JSON.parse($.cookie(columnlistCookieName)); var grid = $("#GridMar").data("kendoGrid"); if (serializedColumns) { grid.columns = serializedColumns; } }
When I hide a column from the grid, the column is hidden and I can see that the cookie now has the right information. When I reload the page however, the column is present in the grid, in the columnmenu however, it is no longer there (see image attached). The columns strasse is visible on the gird, but not in the list of columns that I could make visible or invisible.
Thank you for your suggestions on this issue!