Hi
i have download nice Tools knedo ui and try to use Grid in MVC - it works fine but i have two problems and i don't know how to resolve them
1. i can't get filed from joined table to let me display text filed in my grid as example (Supplier table is joined to Products table in SupplierID) but i can't view CompanyName in my grid i try it as:
columns.Bound(o => o.Supplier).ClientTemplate("#=Supplier.CompanyName#").Width(160);but it make grid now working ?
2. i need to insert dropdownlist in my grid that contain Supplier ID and "CompanyName" but it now working for me too i try add:
model.Field(o => o.SupplierID).DefaultValue(ViewData["defaultCategory"] as AjaxHierarchyEditing.Models.Supplier);
and fill ViewData in Home Controller
my full Code is:
HTML Code:
<divclass="k-rtl"> <scripttype="text/kendo"id="productsTemplate"> @(Html.Kendo().Grid<ProductViewModel>() .Name("Categories_#=CategoryID#") .Columns(columns => { columns.Bound(o => o.ProductName).Width(101).Title("اسم الصنف"); columns.Bound(o => o.UnitPrice).Width(140).Title("سعر الوحده").HeaderHtmlAttributes(new { style = "font-size:12pt;" }); columns.Bound(o => o.QuantityPerUnit).Width(200).Title("الكميه للوحده"); columns.Bound(o => o.ReorderLevel).Width(200).Title("مستوي اعاده الطلب"); columns.Bound(o => o.Supplier).ClientTemplate("#=Supplier.CompanyName#").Width(160); columns.Command(command => { command.Edit(); command.Destroy(); }); }) .ToolBar(tools => tools.Create().Text("اضافه صنف جديد")) .Editable(editable => editable.Mode(GridEditMode.PopUp)) .Pageable() .Sortable() .Filterable() .DataSource(source => source .Ajax() .Model(model => { model.Id(o => o.ProductID); model.Field(o => o.ProductID).Editable(false); model.Field(o => o.SupplierID).DefaultValue(ViewData["defaultCategory"] as AjaxHierarchyEditing.Models.Supplier); }) .Events(events => events.Error("error_handler")) .Read(read => read.Action("Read_Product", "products", new { id = "#=CategoryID#" })) .Update(update => update.Action("Update_Product", "products")) .Create(create => create.Action("Create_Product", "products", new { id = "#=CategoryID#" })) .Destroy(destroy => destroy.Action("Destroy_Product", "products"))) .ToClientTemplate() ) </script></div><divclass="k-rtl"> @(Html.Kendo().Grid<Category>() .Name("Categories_") .Columns(columns => { columns.Bound(e => e.CategoryName).Width(200).Title("اسم المجموعه"); ; columns.Bound(e => e.Description).Width(400).Title("الوصف"); ; columns.Command(command => { command.Edit(); command.Destroy(); }); }) .ToolBar(tools => tools.Create().Text("اضافه مجموعه جديده")) .Editable(editable => editable.Mode(GridEditMode.PopUp)) .Pageable().Sortable().Filterable() .DataSource(source => source.Ajax() .Model(model => { model.Id(e => e.CategoryID); }) .Events(events => events.Error("error_handler")) .Read(read => read.Action("Read_category", "kinds")) .Update(update => update.Action("Update_category", "kinds")) .Create(create => create.Action("Create_category", "kinds")) .Destroy(destroy => destroy.Action("Destroy_category", "kinds"))) .ClientDetailTemplateId("productsTemplate") )</div><scripttype="text/javascript"> function error_handler(e) { productsTemplate if (e.errors) { var message = "Errors:\n"; $.each(e.errors, function (key, value) { if ('errors' in value) { $.each(value.errors, function () { message += this + "\n"; }); } }); alert(message); } }</script>Home Controller Code:
publicActionResult Index(){ PopulateCategories(); returnView();} privatevoidPopulateCategories(){ ViewData["defaultCategory"] = newSelectList(context.Suppliers, "SupplierID", "CompanyName");}Product Controller Read Code:
publicActionResult Read_Product([DataSourceRequest] DataSourceRequest request, intid){ returnJson(context.Products.Where(i => i.CategoryID == id).ToDataSourceResult(request, e => newProductViewModel { ProductID = e.ProductID, ProductName = e.ProductName, QuantityPerUnit = e.QuantityPerUnit, UnitPrice = e.UnitPrice, ReorderLevel = e.ReorderLevel, SupplierID = e.SupplierID, }));} publicProductViewModel() { this.Order_Details = newHashSet<Order_Detail>(); this.units = newHashSet<unit>(); } publicintProductID { get; set; } publicstringProductName { get; set; } publicNullable<int> SupplierID { get; set; } //public Nullable<int> CategoryID { get; set; } publicstringQuantityPerUnit { get; set; } publicNullable<decimal> UnitPrice { get; set; } publicNullable<short> UnitsInStock { get; set; } publicNullable<short> UnitsOnOrder { get; set; } publicNullable<short> ReorderLevel { get; set; } //public bool Discontinued { get; set; } //public string EAN13 { get; set; } publicvirtualCategory Category { get; set; } publicvirtualICollection<Order_Detail> Order_Details { get; set; } publicvirtualSupplier Supplier { get; set; } publicvirtualICollection<unit> units { get; set; }}so please how can i resolve those problems ?