Kendo Grid Custom Filter Dropbox - razor

I am trying to use the custom filtering features of the Kendo Grid. Using Telerik's documentation, I attempted to code the grid per the script below. Notice the "filterable" property on the "Image Type" column. When I pass in a simple boolean true or false, it works. When I use the documentation provided on Telerik's site and pass in a delegate value, it breaks. We're on Kendo version v2013.3.1324. Is this a known issue? Was this area improved after this release?
#(Html.Kendo().Grid<OKN02.Models.ImagingEvent>()
.Name("grid")
.Filterable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Scrollable()
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Columns(columns =>
{
columns.Bound(p => p.ImagingEventId).Hidden();
columns.Bound(p => p.PatientName).Title("Patient Name").Width(90);
columns.Bound(p => p.PatientDOB).Title("DOB").Width(40);
columns.Bound(p => p.Prescriber).Title("Prescriber").Width(80);
columns.Bound(p => p.Site).Title("Site").Width(60);
columns.Bound(p => p.ConfirmationsComplete).Title("Confirmations Complete").Width(90);
columns.Bound(p => p.ImagingDate).Title("Imaging Date").Format("{0:yyyy/MM/dd hh:mm tt}").Width(80);
columns.Bound(p => p.ImageType)
//.Title("Image Type")
.Filterable(filterable => filterable.UI("ImageTypeFilter"))
//.Filterable(true)
.Width(40);
columns.Bound(p => p.OverallStatus).Title("Overall Status").ClientTemplate("#= buildStatusTemplate(OverallStatus) #").Width(40);
})
.Filterable(filterable => filterable
.Extra(true)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
))
)
.Events(events =>
{
events.Change("GridChange");
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.ImagingEventId);
model.Field(p => p.PatientName);
model.Field(p => p.PatientDOB);
model.Field(p => p.Prescriber);
model.Field(p => p.Site);
model.Field(p => p.ImagingDate);
model.Field(p => p.ImagingType);
})
.PageSize(15)
.Read(read => read.Action("MDPortalFiles_Read", "MDPortal").Type(HttpVerbs.Post))
))

Related

Show 2 child grids at the same level in a single parent grid in ASP.NET Kendo MVC

Can anyone please provide me the similar solution using kendo MVC as in the below link?
Creating 2 child kendo grids at the same level
Thanks!
Use the client template features. So on your grid:
#(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.EmployeeViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(e => e.FirstName).Width(130);
columns.Bound(e => e.LastName).Width(130);
columns.Bound(e => e.Country).Width(130);
columns.Bound(e => e.City).Width(110);
columns.Bound(e => e.Title);
})
.Sortable()
.Pageable()
.Scrollable()
>> refer to the template
.ClientDetailTemplateId("template")
... etc
Then make the template with the 2 grids:
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
.Name("grid_#=EmployeeID#") // template expression, to be evaluated in the master context
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(110);
columns.Bound(o => o.ShipCountry).Width(150);
columns.Bound(o => o.ShipAddress).ClientTemplate("\\#= ShipAddress \\#"); // escaped template expression, to be evaluated in the child/detail context
columns.Bound(o => o.ShipName).Width(300);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
#(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
.Name("grid2_#=EmployeeID#") // template expression, to be evaluated in the master context
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(110);
columns.Bound(o => o.ShipCountry).Width(150);
columns.Bound(o => o.ShipAddress).ClientTemplate("\\#= ShipAddress \\#"); // escaped template expression, to be evaluated in the child/detail context
columns.Bound(o => o.ShipName).Width(300);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
</script>
The .ToClientTemplate() is important. Also need to have different grid names for each row. You can mix in other HTML for organization if desired. See here.

Set initial filter on a boolean field column on load

Telerik Kendo MVC Grid - How do I set onload/initial filter equals True with checkbox columns?
I am trying to set a True/False column filter to True on initial load. My Viewmodel has a bool property called IsHoliday. I have followed the example in the link above but i don't have any records showing in the grid at startup. My read action returns a JSON of IEnumerable as suggested in the referenced link. My View is as follows:
#(Html.Kendo().Grid<HolidayVM>()
.Name("h_grid")
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.ServerOperation(false)
.Events(events => events.Error("grid_error")) // Handle the "error" event
.Model(model =>
{
model.Id(m => m.Date);
model.Field(m => m.Date).Editable(false);
})
.Filter(f => f.Add(m => m.IsHoliday.Equals(true)))
.Read(read => read.Action("Holiday_Read", "Holiday"))
.Update(up => up.Action("Holiday_Update", "Holiday").Data("grid_sendAntiForgery"))
)
.Columns(columns =>
{
columns.Bound(p => p.Date).Width(30).Format("{0:dd-MMMM}");
columns.Bound(p => p.HolidayText).Width(100).Filterable(false);
columns.Bound(p => p.IsHoliday)
.ClientTemplate("<input type='checkbox' #= IsHoliday ? '' : checked='checked' # disabled='disabled' />")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("Is equal to")))
.Width(30);
columns.Command(cmd =>
{
cmd.Edit().HtmlAttributes(new { title = "Edit" });
}).Title("Commands").Width(25);
})
.Pageable()
.Sortable()
)
Ideally I will like my grid to look like in attached image, on load, with IsHoliday set to True
I finally figured it out.
.Filter(f => f.Add(m => m.IsHoliday).IsEqualTo(true))
instead of
.Filter(f => f.Add(m => m.IsHoliday.Equals(true)))
use this easily:
columns.Bound(p => p.ISProperty).ClientTemplate("#= ISProperty? 'Yes' : 'No' #")

Kendo MVC Grid - Tab navigation in non editable cells

I am new to kendo mvc grid. I working on an mvc page where I am showing a n kendo grid in which none of the cells are editable.
The requirement is to navigate between the cells while pressing the tab. can someone help me here?
#(Html.Kendo().Grid<History>()
.Name("grid")
.HtmlAttributes(new { style = " max-width: 950px ; width: auto " })
.Columns(columns =>
{
columns.Bound(p => p.JobName).Title("Job Name").Width(150);
columns.Bound(p => p.FileName).Title("File Name");
columns.Bound(p => p.ExecutionOn).Title("Execution Date").Format("{0:MM/dd/yyyy}").Width(100);
columns.Bound(p => p.ExecutionOn).Title("Execution Time").Format("{0:h:mm:ss tt}").Width(100);
columns.Bound(p => p.ExecutionStatus).Title("Execution Status").Width(110);
})
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new int[] { 10, 20, 50, 100})
)
.Sortable()
.Filterable()
.Resizable(r => r.Columns(true))
.ColumnMenu()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Read", "History"))
)
)

Kendo Hierarchical Grids reload data of first opened details grid

I got 2 grids in hierarchy:
#(Html.Kendo().Grid<Model>()
.Name("Obj")
.Columns(columns =>
{
columns.Bound(p => p.ResID).Title("ID").Width(50);
columns.Bound(p => p.Organization).EditorTemplateName("DropdownSupplier").ClientTemplate("#= Organization.Value #").Title("Supplier").Width(160);
columns.Bound(p => p.ResourceType).EditorTemplateName("DropdownResourceType").ClientTemplate("#=ResourceType.Value#").Title("Resource Type").Width(100);
columns.Bound(p => p.ResourceName).Title("Description").Width(150);
columns.Bound(p => p.Quantity).EditorTemplateName("Double").Title("Quantity").Width(120);
columns.Bound(p => p.QuantityUOM).EditorTemplateName("DropdownQuantityUOM").ClientTemplate("#=QuantityUOM.Value#").Title("Quantity UOM").Width(80);
columns.Bound(p => p.Area).ClientTemplate("#= Area.Value #").EditorTemplateName("DropdownAreas").Title("Area of Operation").Width(120);
columns.Bound(p => p.OrderDate).EditorTemplateName("DateTimeSmaller").Title("Order Date").Format("{0:" + format + "}").Width(170);
columns.Bound(p => p.ETA).EditorTemplateName("DateTimeSmaller").Title("ETA").Format("{0:" + format + "}").Width(170);
columns.Bound(p => p.Arrived).EditorTemplateName("Checkbox").Title("Arrived").ClientTemplate("<input type='checkbox' #= Arrived ? checked='checked' : '' # onchange='UpdateResourceArrived(this, \"#=ResourceID#\")' ></input>").Width(60);
columns.Bound(p => p.Status).ClientTemplate("#=Status.Value#").EditorTemplateName("DropdownStatus").Title("Status").Width(100);
columns.Bound(p => p.IsTactical).EditorTemplateName("Checkbox").Title("Tactical").ClientTemplate("<input type='checkbox' #= IsTactical ? checked='checked' : '' # ></input>").Width(60);
columns.Bound(p => p.ResourceID).Title("Resource").HtmlAttributes(new { style = "font-size:1px;" }).Width(1).Hidden(true);
})
.ToolBar(toolbar =>
{
//toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Navigatable()
.Filterable()
.Events(e =>
{
e.Edit("removeValidation");
e.FilterMenuInit("initCheckboxFilter");
e.Change("onSelectedRowChange");
e.DataBound("ResourcesDataBound");
})
.Excel(x => x.FileName("ICS_201-4_IncidentResources.xlsx").AllPages(true).Filterable(true).ProxyURL(Url.Action("Excel_Export_Save", "Grid")))
.Sortable()
.Scrollable(scrollable => scrollable.Height("auto"))
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Groupable()
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events =>
{
events.Error("error_handler");
})
.Model(model =>
{
model.Id(p => p.ResourceID);
model.Field(p => p.ResID).Editable(false);
model.Field(p=>p.Arrived).Editable(false);
model.Field(p => p.Status).DefaultValue(
ViewData["defaultStatus"] as MinifiedKeyValueModel);
model.Field(p => p.Area).DefaultValue(
ViewData["defaultAreas"] as MinifiedKeyValueModel);
model.Field(p => p.Organization).DefaultValue(
ViewData["defaultSupplier"] as MinifiedKeyValueModel);
model.Field(p => p.ResourceType).DefaultValue(
ViewData["defaultResourceType"] as MinifiedKeyValueModel);
model.Field(p => p.QuantityUOM).DefaultValue(
ViewData["defaultQuantityUOM"] as MinifiedKeyValueModel);
})
.Read(read =>
read.Action("Resources_Read", "ICSForms")
.Data("filterByPeriod")
)
.Create("Resources_Create", "ICSForms")
.Update(x=>x.Action("Resources_Update", "ICSForms"))
.Destroy(destroy => destroy.Action("Resources_Destroy", "ICSForms")).AutoSync(true)
)
.ClientDetailTemplateId("rTemplate")
)
and:
<script type="text/kendo" id="rTemplate">
#(Html.Kendo().Grid<Model>()
.Name("childObj")
.Columns(columns =>
{
columns.Bound(p => p.ResID).Title("ID").Width(50);
columns.Bound(p => p.Organization).ClientTemplate("\\#=Organization.Value\\#").Title("Supplier").Width(160);
columns.Bound(p => p.ResourceType).ClientTemplate("\\#=ResourceType.Value\\#").Title("Resource Type").EditorTemplateName("DropdownResourceType").Width(100);
columns.Bound(p => p.ResourceName).Title("Description").Width(150);
columns.Bound(p => p.Quantity).EditorTemplateName("Double").Title("Quantity").Width(120);
columns.Bound(p => p.QuantityUOM.Value).EditorTemplateName("DropdownQuantityUOM").ClientTemplate("#=QuantityUOM.Value#").Title("Quantity UOM").Width(80);
columns.Bound(p => p.Area).ClientTemplate("\\#=Area.Value\\#").EditorTemplateName("DropdownAreas").Title("Area of Operation").Width(120);
columns.Bound(p => p.OrderDate).EditorTemplateName("DateTimeSmaller").Title("Order Date").Width(170).Format("{0:" + DependencyResolver.Current.GetService<IAP.Helpers.IApplicationOptionsProvider>().GetDataFormat(false, true) + "}"); ;
columns.Bound(p => p.ETA).EditorTemplateName("DateTimeSmaller").Title("ETA").Width(170).Format("{0:" + DependencyResolver.Current.GetService<IAP.Helpers.IApplicationOptionsProvider>().GetDataFormat(false, true) + "}"); ;
columns.Bound(p => p.Arrived).EditorTemplateName("Checkbox").Title("Arrived").ClientTemplate("<input type='checkbox' \\#= Arrived ? checked='checked' : '' \\# onchange='UpdateResourceArrived(this, \"#=ResourceID#\")' ></input>").Width(60);
columns.Bound(p => p.Status).ClientTemplate("\\#=Status.Value\\#").EditorTemplateName("DropdownStatus").Title("Status").Width(100);
columns.Bound(p => p.IsTactical).EditorTemplateName("Checkbox").Title("Tactical").ClientTemplate("<input type='checkbox' \\#= IsTactical ? checked='checked' : '' \\# ></input>").Width(60);
columns.Bound(p => p.ResourceID).Title("Resource").HtmlAttributes(new { style = "font-size:1px;width:1px;max-width:1px;" }).Width(1).Hidden(true);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Navigatable()
.Filterable()
.Events(e =>
{
e.Edit("removeValidation");
e.FilterMenuInit("initCheckboxFilter");
e.Change("onSelectedRowChange");
})
.Sortable()
.Scrollable(scrollable => scrollable.Height(120))
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Groupable()
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.ResourceID);
model.Field(p => p.ResourceID).Editable(false);
model.Field(p => p.ResID).Editable(false);
model.Field(p => p.Status).DefaultValue(
ViewData["defaultStatus"] as MinifiedKeyValueModel);
model.Field(p => p.Area).DefaultValue(
ViewData["defaultAreas"] as MinifiedKeyValueModel);
model.Field(p => p.Organization).DefaultValue(
ViewData["defaultSupplier"] as MinifiedKeyValueModel);
model.Field(p => p.ResourceType).DefaultValue(
ViewData["defaultResourceType"] as MinifiedKeyValueModel);
model.Field(p => p.QuantityUOM).DefaultValue(
ViewData["defaultQuantityUOM"] as MinifiedKeyValueModel);
})
.Read(read =>
read.Action("ResourcesChildren_Read", "ICSForms",
new { resourceID = "#=ResourceID#" }))
.Update(update => update.Action("Resources_Update", "ICSForms"))
.Destroy(destroy => destroy.Action("Resources_Destroy", "ICSForms")).AutoSync(true)
).ToClientTemplate()
)
</script>
The problem is that if I open the details of one of the rows and I see everything that has that parent (so far so good) and I open another details grid it opens an empty one and the first one refreshes its data with the ids of the second opened element.
I researched this issue, but I couldn't find similar occurrences. Any help solving this would be much appreciated.
You need a unique name for every instance of a grid.
<script type="text/kendo" id="rTemplate">
#(Html.Kendo().Grid<Model>()
.Name("childObj_#=ResID#") //Assuming ResID is the parent model's ID (I think #=id# would work as well if you have set the Id in the model)
[...]
If you use $("#childObj") anywhere, you will have to refactor that somehow.

Column with menu in each cell with menu items

I want to create a menu item in each cell using Kendo Grid MVC I have managed to get the grid to display with the menu item in each cell but when I click on the menu I don't see the menu items.
Need the menu items to show in their own column this is why I have not bound it to a specific property.
Any ideas on what I'm doing wrong?
#(Html.Kendo().Grid(Model)
.Name("gridDropDownMenu")
.Columns(columns =>
{
columns.Template(#<text></text>).Title("").Width(120).HtmlAttributes(new { #class = "templateCell" }).ClientTemplate(
Html.Kendo().Menu()
.Name("menu_#=ProductID#")
.Items(its =>
{
its.Add().Text("Actions").Items(nested =>
{
nested.Add().Text("Test 1");
nested.Add().Text("Test 2");
});
})
.ToClientTemplate().ToHtmlString()
);
columns.Bound(p => p.ProductName);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Scrollable()
.HtmlAttributes(new { style = "height:250px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(20)
.ServerOperation(false)
.Events(events => events.Error("errorHandler"))
.Model(model =>
{
model.Id(p => p.ProductID);
//model.Field(p => p.ProductID).Editable(true);
model.Field(p => p.CategoryID).DefaultValue(1);
})
.Read(read => read.Action("ForeignKeyColumn_Read", "Home"))
.Update(update => update.Action("ForeignKeyColumn_Update", "Home"))
.Create(create => create.Action("ForeignKeyColumn_Create", "Home"))
.Destroy(destroy => destroy.Action("ForeignKeyColumn_Destroy", "Home"))
)
)
Resolved by adding the following: .Events(ev => ev.DataBound("initMenus"))
function initMenus(e) {
$(".templateCell").each(function(){
eval($(this).children("script").last().html());
});
}