Conditionally Display ClientTemplate for Kendo UI Grid using Razor Variable - kendo-grid

I need to conditionally display buttons in a client template based on a razor variable. Here is where I get the variable:
#{
ViewBag.Title = "CompetencyConfiguration";
Layout = "~/Views/Shared/_Layout.cshtml";
var User = Model.UserInfo;
var IsiCanAssessor = Model.UserInfo.PermissionRole.RoleId == 4 || Model.UserInfo.PermissionRole.RoleId == 1 ? true : false;
}
Here is my Grid:
#(Html.Kendo().Grid<CN.Models.Competency.ViewModels.AssessmentModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.AssessmentId).Hidden();
columns.Bound(c => c.AssessmentName).Width(250);
columns.Bound(c => c.CompetencyType).Width(80);
columns.Bound(c => c.CompanyName).Width(200);
columns.Bound(c => c.NumOfUnits).Width(50);
columns.Template(#<text></text>).Title("Actions")
.Width(150)
.ClientTemplate(
"# if(#IsiCanAssessor == true) {#" +
"<div class='btn btn-alt3' style='cursor:pointer' onclick='editRow()'><i class='la la-edit'></i>Edit</div><div class='btn btn-alt3' style='cursor:pointer' onclick='downloadAssessment()'><i class='lnir lnir-download'></i>Download</div><div id='deleteAssessment' class='btn btn-alt3' style='cursor: pointer;' onclick='deleteAssessment(this)'><i class='la la-trash'></i>Delete</div>"+
"# } #");
})
.Height(850)
.Scrollable()
.Sortable()
.Selectable()
.ClientDetailTemplateId("template")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetAssessmentSearch", "Config", new { area = "Competency" }))
.Model(m => m.Id(o => o.AssessmentId))
)
)
I also tried like this:
#(Html.Kendo().Grid<CN.Models.Competency.ViewModels.AssessmentModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.AssessmentId).Hidden();
columns.Bound(c => c.AssessmentName).Width(250);
columns.Bound(c => c.CompetencyType).Width(80);
columns.Bound(c => c.CompanyName).Width(200);
columns.Bound(c => c.NumOfUnits).Width(50);
columns.Template(#<text>
#if (IsiCanAssessor == true)
{
<div class='btn btn-alt3' style='cursor:pointer' onclick='editRow()'><i class='la la-edit'></i>Edit</div><div class='btn btn-alt3' style='cursor:pointer' onclick='downloadAssessment()'><i class='lnir lnir-download'></i>Download</div><div id='deleteAssessment' class='btn btn-alt3' style='cursor: pointer;' onclick='deleteAssessment(this)'><i class='la la-trash'></i>Delete</div>
}
</text>).Title("Actions")
.Width(150);
})
.Height(850)
.Scrollable()
.Sortable()
.Selectable()
.ClientDetailTemplateId("template")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetAssessmentSearch", "Config", new { area = "Competency" }))
.Model(m => m.Id(o => o.AssessmentId))
)
)

I was able to figure out the proper syntax. This works beautifully:
#(Html.Kendo().Grid<CN.Models.Competency.ViewModels.AssessmentModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.AssessmentId).Hidden();
columns.Bound(c => c.AssessmentName).Width(250);
columns.Bound(c => c.CompetencyType).Width(80);
columns.Bound(c => c.CompanyName).Width(200);
columns.Bound(c => c.NumOfUnits).Width(50);
columns.Bound(c => c.CompetencyTypeId).Hidden();
columns.Template(#<text></text>).Title("Actions")
.Width(150)
.ClientTemplate(
"# if('" + #IsiCanAssessor +"'== 'True') {#" +
"<div class='btn btn-alt3' style='cursor:pointer' onclick='editRow()'><i class='la la-edit'></i>Edit</div><div class='btn btn-alt3' style='cursor:pointer' onclick='downloadAssessment()'><i class='lnir lnir-download'></i>Download</div><div id='deleteAssessment' class='btn btn-alt3' style='cursor: pointer;' onclick='deleteAssessment(this)'><i class='la la-trash'></i>Delete</div>"+
"# } #");
})
.Height(850)
.Scrollable()
.Sortable()
.Selectable()
.ClientDetailTemplateId("template")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetAssessmentSearch", "Config", new { area = "Competency" }))
.Model(m => m.Id(o => o.AssessmentId))
)
)

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>

Kendo Grid Exporting of Live Data

For the life of me, I cannot determine a solution to this. I have a Kendo Grid that grabs random part numbers for an audit. However, when I export the grid to Excel, it executes the datasource again, resulting in different part numbers.
I would like to just export what is displayed on the screen and not execute the datasource again.
How do I do this?
Here is a subset of the code:
<section class="panel">
#(Html.Kendo().Grid<DTO.GenerateRandomPartNumsList>()
.Name("RandomNumberGeneratorGrid")
.Columns(columns => {
columns.Bound(p => p.VendorName).ClientTemplate("<div class='cell-with-copy'><div>#:VendorName #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
columns.Bound(p => p.PartNo).ClientTemplate("<div class='cell-with-copy'><div>#:PartNo #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
columns.Bound(p => p.OnHand).ClientTemplate("<div class='cell-with-copy'><div>#:OnHand #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
columns.Bound(p => p.PartDesc).ClientTemplate("<div class='cell-with-copy'><div>#:PartDesc #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
columns.Bound(p => p.Bin).ClientTemplate("<div class='cell-with-copy'><div>#:Bin #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
columns.Bound(p => p.PackageQuantity).ClientTemplate("<div class='cell-with-copy'><div>#:PackageQuantity #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
columns.Bound(p => p.Cost).ClientTemplate("<div class='cell-with-copy float-right'><div>#:Cost #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
columns.Bound(p => p.TotalValue).ClientTemplate("<div class='cell-with-copy float-right'><div>#:TotalValue #</div><i class='fas fa=clipboard icon-copy'></i></div>")
.HtmlAttributes(new { #class = "k-hover" }).Width(125);
})
.Pageable(pager => pager.AlwaysVisible(true).PageSizes(new int[] {minRecords,
(minRecords * 2),
(minRecords * 3),
(minRecords * 4)}))
.Sortable()
.Resizable(resize => resize.Columns(true))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Cell))
.Navigatable()
.Events(ev => ev.Change("copyCell"))
.AllowCopy(true)
.Scrollable()
//.Filterable()
.ToolBar(toolbar => {
toolbar.ClientTemplateId("RandomNumberGeneratorToolBar");
})
.Excel(excel=>excel
.FileName("RandomPartNumbers.xlsx")
.AllPages()
.ProxyURL(Url.Action("Excel_Export_Save", "RandomPartNumbers"))
)
.Pdf(pdf => pdf
.AllPages()
.AvoidLinks()
.PaperSize("A4")
.Margin("2cm", "1cm", "1cm", "1cm")
.RepeatHeaders()
.Landscape()
.Scale(.5)
.TemplateId("page-template")
.FileName("RandomPartNums.pdf")
.ProxyURL(Url.Action("Pdf_Export_Save", "RandomPartNums"))
)
.Search(search =>
{
search.Field(f => f.VendorName)
.Field(f => f.PartNo)
.Field(f => f.PartDesc)
.Field(f => f.Bin);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(minRecords)
.Read(read => read.Action("ReadRandomPartsNumbers", "Parts")
.Data("getFilterData"))
)
.LoaderType(Kendo.Mvc.UI.GridLoaderType.LoadingPanel)
)
</section>
Thanks to Tawab Wakil for finding this:
Reference: Kendo Grid MVC / export to Excel without additional request
.DataSource(ds => ds
.Ajax()
.PageSize(30)
.Read(r => r.Action("GetTaskItems", "Home")
.Type(HttpVerbs.Get))
.ServerOperation(false)
))
The .ServerOperation(false) is what did the trick

writing a script/Function for checkboxes and Custom Delete button in Telerik UI for ASP.NET MVC

I need help writing a script/Function for my Telerik UI for asp.net MVC program. I have a delete button in my tool bar and I think my script is correct for it deleting. Now, I'm told that my check boxes haft to have a script also to be deleted when checked. As a C# coder, I'm not entirely knowledgeable about Json coding. So, any help would be appreciated! Here is my code below.
#(Html.Kendo().Grid<MVCSQLDatabase.Models>()
.Name("Grid")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Batch(true)
.Model(model => model.Id(p => p.Proposal_Uid))
.Read(read => read.Action("Proposals_Read", "Grid"))
.Create(create => create.Action("Proposals_Create", "Grid"))
.Update(update => update.Action("Proposals_Update", "Grid"))
.Destroy(destroy => destroy.Action("Proposals_Destroy", "Grid"))
)
.Resizable(resize => resize.Columns(true))
.Columns(columns =>
{
columns.Select().Width(100); //<-- my check boxes code.
columns.Bound(c => c.Prime).Width(215);
columns.Bound(c => c.Proposal).Width(200);
columns.Bound(c => c.C).Width(190);
columns.Bound(c => c.Cl).Width(185);
columns.Bound(c => c.T).Width(290);
columns.Bound(c => c.M).Width(220);
columns.Bound(c => c.S).Format("{0: dd/MM/yyyy}").Width(170);
columns.Bound(c => c.E).Format("{0: dd/MM/yyyy}").Width(170);
columns.Bound(c => c.P).Width(235);
columns.Bound(c => c.Con).Width(215);
columns.Command(command => { command.Destroy(); }).Width(180);// <--- My delete button in my column
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
toolbar.Excel();
toolbar.Custom().Text("Delete").Name("batchDestroy").IconClass("k-icon k-i-close"); //<-- my custom made delete button in my toolbar.
})
.ColumnMenu()
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Selectable(selectable =>
{
selectable.Mode(GridSelectionMode.Multiple);
selectable.Type(GridSelectionType.Row);
})
.PersistSelection()
.Filterable(filterable => filterable.Mode(GridFilterMode.Row))
.Scrollable()
.HtmlAttributes(new { style = "height:835px;" })
)
<script>
$("#grid").on("click", "batchDestroy", function() {
var $tr = $(this).closest("tr"),
grid = $("#grid").data("kendoGrid"),
dataItem = grid.dataItem($tr);
grid.dataSource.remove(dataItem);
});
</script>
Here is the code for anybody else stuck in this situation. The thing that got me the most, was the .done function to end the button click function and then saving the grid AFTER the delete was made. Hopefully, this helps others!
<script>
$(document).ready(function ()
{
$(".k-grid-Destroy").on("click", function (e)
{
e.preventDefault();
var grid = $("#Grid").data("kendoGrid");
var selectedRows = grid.select();
kendo.confirm(kendo.format("Are you sure you wish to delete {0} records?", selectedRows.length))
.done(function ()
{
$.each(selectedRows, function (i, row)
{
grid.removeRow(row);
})
grid.saveChanges();
});
});
});
</script>

Kendo grid column - show text when editing

I have a kendo grid in a page
I need to show a text when the user start editing a specified column from the grid.
Here is the grid:
#(Html.Kendo().Grid<GGISServices.Models.SilviPrio.GenerateDocumentViewModel>()
.Name("grid")
.AutoBind(false)
.Columns(columns =>
{ ...
columns.Bound(c => c.TreeQ4)
.HeaderTemplate("<a class='k-link' href=''>"+ LanguageService.Instance.Translate("Enum_TreeGroup_4") +"<br><span class='subtitle'>" + LanguageService.Instance.Translate("Trees_MeasurementUnits") + "</span></a>")
.HtmlAttributes(new { #class = "tree-q4 pvrf-data tree-column" }).Sortable(true)
.Filterable(f => f.Multi(true).DataSource(ds => ds.Read(r => r.Action("GetFilterData", "Document", new { Area = GGISWeb.AreaModules.SilviPrio }).Type(HttpVerbs.Post).Data("{ field: 'TreeQ4', fieldtype: 'decimal' }"))));
columns.Bound(c => c.TreeQ1)
.HeaderTemplate("<a class='k-link' href=''>" + LanguageService.Instance.Translate("Enum_TreeGroup_1") + "<br><span class='subtitle'>" + LanguageService.Instance.Translate("Trees_MeasurementUnits") + "</span></a>")
.HtmlAttributes(new { #class = "tree-q1 pvrf-data tree-column" }).Sortable(true)
.Filterable(f => f.Multi(true).DataSource(ds => ds.Read(r => r.Action("GetFilterData", "Document", new { Area = GGISWeb.AreaModules.SilviPrio }).Type(HttpVerbs.Post).Data("{ field: 'TreeQ1', fieldtype: 'decimal' }"))));
columns.Bound(c => c.TreeQ2)
.HeaderTemplate("<a class='k-link' href=''>" + LanguageService.Instance.Translate("Enum_TreeGroup_2") + "<br><span class='subtitle'>" + LanguageService.Instance.Translate("Trees_MeasurementUnits") + "</span></a>")
.HtmlAttributes(new { #class = "tree-q2 pvrf-data tree-column" }).Sortable(true)
.Filterable(f => f.Multi(true).DataSource(ds => ds.Read(r => r.Action("GetFilterData", "Document", new { Area = GGISWeb.AreaModules.SilviPrio }).Type(HttpVerbs.Post).Data("{ field: 'TreeQ2', fieldtype: 'decimal' }"))));
columns.Bound(c => c.TreeQ5)
.HeaderTemplate("<a class='k-link' href=''>" + LanguageService.Instance.Translate("Enum_TreeGroup_5") + "<br><span class='subtitle'>" + LanguageService.Instance.Translate("Trees_MeasurementUnits") + "</span></a>")
.HtmlAttributes(new { #class = "tree-q5 pvrf-data tree-column" }).Sortable(true)
.Filterable(f => f.Multi(true).DataSource(ds => ds.Read(r => r.Action("GetFilterData", "Document", new { Area = GGISWeb.AreaModules.SilviPrio }).Type(HttpVerbs.Post).Data("{ field: 'TreeQ5', fieldtype: 'decimal' }"))));
columns.Bound(c => c.TreeQ3)
.HeaderTemplate("<a class='k-link' href=''>" + LanguageService.Instance.Translate("Enum_TreeGroup_3") + "<br><span class='subtitle'>" + LanguageService.Instance.Translate("Trees_MeasurementUnits") + "</span></a>")
.HtmlAttributes(new { #class = "tree-q3 pvrf-data tree-column" }).Sortable(true)
.Filterable(f => f.Multi(true).DataSource(ds => ds.Read(r => r.Action("GetFilterData", "Document", new { Area = GGISWeb.AreaModules.SilviPrio }).Type(HttpVerbs.Post).Data("{ field: 'TreeQ3', fieldtype: 'decimal' }"))));
columns
.Bound(c => c.SilviPrioId)
.ClientTemplate(
"#= actionDetails(data) #"
)
.Title(LanguageService.Instance.Translate("GridLabel_Action"))
.Filterable(false)
.Sortable(false)
.HtmlAttributes(new { #class = "action-column" });
})
.ToolBar(toolbar =>
{
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Sortable()
.Filterable()
//.Selectable(selection => selection.Enabled(true))
.Selectable(selection => selection.Mode(GridSelectionMode.Single))
//.Events(e => e.DataBound("SaveState").ExcelExport("ShowLoading"))
.Pageable(pageable => pageable
.Refresh(true)
.Info(true)
.PageSizes(new int[] { 5, 10, 25, 50, 100, 1000 })
.ButtonCount(5)
)
.Events(events => events
.Change("onChange")
.DataBound("onDataBound")
.DataBinding("onDataBounding")
.Edit("onEditing")
.SaveChanges("onSavingChanges")
)
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.Events(events => events
.Error("error_handler")
.RequestEnd("request_end_handler")
)
.Model( model =>
{
model.Id(p => p.SilviPrioId);
model.Field(p => p.Region).Editable(false);
model.Field(p => p.CostCenter).Editable(false);
model.Field(p => p.UP).Editable(false);
model.Field(p => p.UA).Editable(false);
model.Field(p => p.MeasurementUnit).Editable(false);
model.Field(p => p.PlannedQuantity).Editable(false);
model.Field(p => p.PlannedUnitPrice).Editable(false);
})
.Read(read => read.Action("GetData", "Document", new { Area = GGISWeb.AreaModules.SilviPrio }))
.Update(update => update.Action("Editing_Update", "Document", new { Area = GGISWeb.AreaModules.SilviPrio }).Data("additionalUpdateInfo"))
.PageSize(25)
)
.Resizable(resize => resize.Columns(true))
)
I need to show a text, something like this,
enter image description here
but immediately when the user starts editing the fields TreeQ4, TreeQ1
I have searched on the net, and I have founded something with the HtmlAttributes(title, but it is not working like this.
Can you please advise how can I resolve?
Use the kendo grid edit event and then append the text to a html element in the event function.

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.