Kendo Hierarchical Grids reload data of first opened details grid - kendo-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.

Related

Telerik Net Core Grid, display checkbox column in TileLayout

Telerik Net Core Grid, display checkbox column in TileLayout.
Without TileLayout grid is working fine. But in TileLayout when i using ClientTemplate to show checkbox,compiler give me error:'Uncaught ReferenceError: Id is not defined'.I'm assuming it's related to the nested ClientTemplate, but how to avoid this problem to display the checkbox?
#(Html.Kendo().TileLayout()
.Name("tilelayout")
.Columns(100)
.RowsHeight("100%")
.Height("100%")
.ColumnsWidth("100%")
.Containers(c => {
c.Add().Header(h => h.Text("Входящие документы")).BodyTemplateId("inboxdocuments").ColSpan(75).RowSpan(2);
c.Add().Header(h => h.Text("Прикрепленные документы")).BodyTemplateId("attachments").ColSpan(25).RowSpan(1);
c.Add().Header(h => h.Text("Рассылка")).BodyTemplateId("distributions").ColSpan(25).RowSpan(1);
})
.Reorderable()
.Resizable()
.Events(e=>e.Resize("onTileResize"))
)
```
<script id="inboxdocuments" type = "text/x-kendo-template">
<input type="hidden" id="DocumentId" value="">
#(Html.Kendo().Grid<Billing.Workflow.Models.DTO.InboxDocumentDTO>()
.Name("InboxDocumentsGrid")
.Columns(columns =>
{
columns.Bound(e => e.Id).Title("№").Width(100);
columns.Bound(e => e.RegistrationDate).Title("Дата").Format("{0: dd.MM.yyyy}").Width(125);
columns.Bound(e => e.RegistrationNumber).Title("№ документа").Width(150);
columns.Bound(e => e.Applicant).Title("Откуда").Width(250);
columns.Bound(e => e.DeadlineDate).Title("Срок до").Format("{0: dd.MM.yyyy}").Width(125);
**columns.Bound(e => e.IsForInformation).ClientTemplate("<input type='checkbox' value='#= Id #' " + "# if (IsForInformation) { #" + "checked='checked'" + "# } #" + "/>").Title("Для информации").Width(150);**
columns.Bound(e => e.IsForControl).Title("Для контроля").Width(150);
columns.Bound(e => e.ReminderDate).Title("Дата напоминания").Format("{0: dd.MM.yyyy}").Width(200);
columns.Bound(e => e.User).Title("Пользователь").Width(300);
columns.Bound(e => e.Account).Title("ЛС/№ контракта").Width(200);
columns.Bound(e => e.ApplicantFullName).Title("ФИО").Width(300);
columns.Bound(e => e.ApplicantAddress).Title("Адрес").Width(300);
columns.Bound(e => e.DocumentNumber).Title("Входящий номер").Width(200);
columns.Bound(e => e.DocumentDate).Title("Дата вх.документа").Format("{0: dd.MM.yyyy}").Width(125);
columns.Bound(e => e.Summary).Title("Краткое содержание").Width(300);
columns.Bound(e => e.Note).Title("Комментарий").Width(500);
columns.Bound(e => e.Mail).Title("Эл.адрес").Width(200);
})
.ToolBar(toolbar =>
{
toolbar.Excel();
toolbar.Custom().Text("Создать входящий документ").IconClass("k-icon k-i-download");
toolbar.Custom().Text("Создать исходящий документ").IconClass("k-icon k-i-upload");
toolbar.Search();
}
)
.Mobile()
.Pageable()
.Scrollable()
.Sortable()
.Filterable()
.Selectable()
.Navigatable()
.ColumnMenu()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "height:99%" })
.DataSource(datasource =>
datasource
.Ajax()
.PageSize(100)
/*.ServerOperation(false)*/
.Read(read => read.Action("GetInboxDocuments", "Reception"))
)
.Events
(
events=>events
.Change("onChange")
.DataBound("onInboxdocumentsDataBound")
)
.Excel(excel => excel
.Collapsible(true)
.AllPages(true))
.ToClientTemplate()
)
</script>

Newly added row gets disappear in kendo grid

I have a kendo grid and a AddRow button.On AddRow Button click I am adding a new row to kendo grid.When I click on AddRow button, new row gets added sucessfully but clicking anywhere else in the page except first column of newly added row,row disappears.Here is my code on button click:
$('#AddRow').click(function () {
grid = $('#grdclaimantTypeTips').data("kendoGrid");
grid.addRow();
row = grid.tbody.find(".k-grid-edit-row");
grid.select(row);
}
Here is my code for kendo grid:
#(Html.Kendo().Grid<ClaimPro.Data.ClientAttributeDO>()
.Name("grdclaimantTypeTips")
.Columns(columns =>
{
columns.Bound(Type => Type.claim_type_name).Title(Resource.ClaimType).Width(80).EditorTemplateName("ClientAttributesDDL").EditorViewData(new { columnName = "claim_type_cd" });
columns.Bound(Type => Type.claimant_name).Title(Resource.Claimant).Width(120).ClientTemplate("#=claimant_name_changed#");
columns.Bound(Type => Type.tip).Title(Resource.Tip).Width(200).HtmlAttributes(new { #class = "Wrap" });
columns.Bound(Type => Type.tip).Hidden();
columns.Bound(Type => Type.tip).Hidden();
columns.Bound(Type => Type.id).Hidden();
})
.Scrollable()
.Sortable()
.Filterable()
.Selectable(selectable =>
{
selectable.Mode(GridSelectionMode.Single);
selectable.Type(GridSelectionType.Row);
}
)
.Pageable(pageable => pageable.Input(true).PageSizes((int[])ViewData["DefaultDropdownSize"]))
.Resizable(resize => resize.Columns(true))
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Events(e => e.Edit("onEditGrid"))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Batch(true)
.Model(model => model.Id(c => c.id))
.Model(model => model.Field(p => p.claimant_name).Editable(false))
.Read(read => read.Action("GetClaimantTypeDetails", "ClientAttribute"))
)
)

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());
});
}

Kendo Grid Custom Filter Dropbox

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))
))

Kendo, Razor braces problems

I checked braces, brackets 100 times...I think they are correctly placed but I get
"Keyword, identifier, or string expected after verbatim specifier: #"
<script id="customercontactsTemplate" type="text/kendo-tmpl">
#(Html.Kendo().TabStrip()
.Name("TabStripCustomer")
.SelectedIndex(0)
.Items(items =>
{
items.Add().Text("Contacts").Content(obj =>
#(Html.Kendo().Grid<ModelApp.Models.CustomerContacts>()
.Name("customercontacts")
.Columns(columns =>
{
columns.Bound(l => l.CustomerContactID);
columns.Bound(l => l.CustomerID);
columns.Bound(l => l.CustomerContactName);
columns.Bound(l => l.CustomerContactPhone);
columns.Bound(l => l.CustomerContactDuty);
})
.DataSource(dataSource => dataSource
.Ajax()
.Model
(model=>{
model.Id(l => l.CustomerContactID);
model.Field(l=>l.CustomerContactID).Editable(false);
model.Field(l => l.CustomerID);
model.Field(l => l.CustomerContactName);
model.Field(l => l.CustomerContactPhone);
model.Field(l => l.CustomerContactDuty);
}
)
.Read(read => read.Action("CustomersContactsRead", "Customers", new { customerID = "#=CustomerID#" }))
.Update(update => update.Action("CustomersContactsEdit", "Customers"))
.Create(update => update.Action("CustomersContactsCreate", "Customers", new { customerID = "#=CustomerID#" }))
)
.Events(e => e.Edit("onEdit"))
.Pageable()
.Sortable()
.Editable(editing => editing.Mode(GridEditMode.InCell))
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.ToClientTemplate())
);}))
Is there a braces code checker? Can you spot any error?
Thanx in advance!
The problem is this line
Content(obj => #(Html.Kendo().Grid<ModelApp.Models.CustomerContacts>()
In razor you should use template delegates:
Content(#<text>
#(Html.Kendo().Grid<ModelApp.Models.CustomerContacts>()