I have a Hierarchical grid and I'm trying to add a custom editor for pop-up editing. When I add the template to the child grid and click on the "edit" button, i get a invalid template error. If i add that same template to the parent, it works fine.
Here is the error in console:
Uncaught Error: Invalid template:'
Here is the code
#(Html.Kendo().Grid<ParentViewModel>()
.Name("GridAdjax")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Read(read => read.Action("Read", "controller"))
.Model(model =>
{
model.Id(c => c.Id);
})
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Events(events => events.RequestEnd("onRequestEnd"))
)
.Columns(columns =>
{
columns.Bound(p => p.CompanyName).Title("Company Name");
columns.Bound(p => p.CompanyDomain).Title("Company Domain");
columns.Bound(p => p.CompanySecurityRole).Title("Security Role");
columns.Bound(p => p.CompanySecurityGroup).Title("Security Group");
})
.ClientDetailTemplateId("template")
.Pageable()
.Sortable()
.Resizable(resize => resize.Columns(true))
.Events(e => e.DataBound("OnDataBound"))
.Deferred()
)
<CHILD>
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().Grid<ChildlViewModel>()
.Name("grid_#=CompanyId#")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Update(update => update.Action("CompanyList_Update", "Administration"))
.Read(read => read.Action("Read", "Child", new { companyId = "#=CompanyId#" }))
.Model(model =>
{
model.Id(c => c.Id);
model.Field(c => c.CompanySoldTo).Editable(true);
model.Field(c => c.CompanyDistributionChannel).Editable(true);
model.Field(c => c.CompanyDivision).Editable(true);
model.Field(c => c.CompanyPlant).Editable(true);
model.Field(c => c.CompanySalesOrg).Editable(true);
})
)
.Columns(columns =>
{
columns.Bound(p => p.CompanySoldTo).Title("Sold To");
columns.Bound(p => p.CompanyDistributionChannel).Title("Dist. Chan.");
columns.Bound(p => p.CompanyPlant).Title("Plant");
columns.Bound(p => p.CompanySalesOrg).Title("Sales Org");
columns.Command(command => { command.Edit(); }).Title(("Edit SAP Info."));
})
.Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("Detail"))
.Pageable()
.Sortable()
.ToClientTemplate()
)
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
If anyone experiences this issue in the future, the problem was actually in my custom pop-up editor template. I had a data validation message on one of the input boxes set as "Please enter your account #". The "#" was being interpreted as a template by Kendo. I escaped the # and then was able to get it to successfully load.
Related
I have code that looks as follows:
#(Html.Kendo().Grid<JeffreysOnline.Entities.Customer>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.LastName).Width(150);
columns.Bound(p => p.FirstName).Width(125);
columns.Bound(p => p.MiddleInitial).Width(75);
columns.Bound(p => p.Phone).Width(125);
columns.Bound(p => p.Address).Width(150);
columns.Bound(p => p.City).Width(100);
columns.Bound(p => p.State).Width(50);
columns.Bound(p => p.Zip).Width(125);
columns.Bound(p => p.TaxName).Width(125);
columns.Bound(p => p.TaxId).Width(125);
columns.Bound(p => p.BadChecks).Width(125);
columns.Bound(p => p.OtherRisk).Width(125);
columns.Bound(p => p.Interests).Width(125);
columns.Bound(p => p.BirthDate).Width(125);
columns.Bound(p => p.BouncedCheck).Width(125);
columns.Bound(p => p.PCNumber).Width(125);
columns.Bound(p => p.Comments).Width(125);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
toolbar.Excel();
})
.Editable(editable => editable.Mode(GridEditMode.InCell)) // In-cell editing instead of the whole row
.Pageable()
.Navigatable() // This allows the user to tab between columns in the grid.
.Sortable()
.Scrollable()
.Groupable()
.Excel(excel => excel
.FileName("Customers.xlsx")
.Filterable(true)
.AllPages(false)
.ProxyURL(Url.Action("ExcelExport", "Customer"))
)
.HtmlAttributes(new { style = "height:700px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true) // We want to perform batch operations
.PageSize(500) // Set the page size
.Events(events => events.Error("error_handler")) // Define a function that gets called on an error
.Model(model => model.Id(p => p.RowId)) // Define the PK
.Create(update => update.Action("Create", "Customer")) // The Create method in the controller
.Read(read => read.Action("Read", "Customer")) // The Read method in the controller
.Update(update => update.Action("Update", "Customer")) // The Update method in the controller
.Destroy(update => update.Action("Delete", "Customer")) // The Delete method in the controller
)
When the grid renders on the page, an Edit button appears in the last column:
Why is this edit button appearing when I have in-cell editing mode set?
Do you mean the Edit button? You're adding it in your code here:
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
Remove the command.Edit(); statement and the button should disappear.
This is my code:
#(Html.Kendo().Grid<RMS.Admin.ViewModel>()
.Name("ResourceGrid")
.Columns(columns =>
{
columns.Bound(c => c.ResourceName);
columns.Bound(c => c.Descritption);
columns.Bound(c => c.ResourceType).ClientTemplate("#=ResourceType.Name#");
columns.Bound(c => c.Approved);
columns.Bound(c => c.IsEnabled);
columns.Bound(c => c.Data).Width(220);
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(172).Title("Edit/Delete");
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Scrollable()
.Sortable()
.HtmlAttributes(new { style = "height:800px" })
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.ClientDetailTemplateId("template")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(s => s.ResourceId);
model.Field(p => p.ResourceType).DefaultValue(ViewData["defResourceType"] as RMS.Admin.ViewModel.ResourceTypeId);
})
.Create(update => update.Action("CreateResource", "Home", new { resourceTypeId = "#=ResourceType.Id#" }))
.Read(read => read.Action("ReadResource", "Home"))
.Update(update => update.Action("SaveSystem", "Home"))
.Destroy(destroy => destroy.Action("RemoveSystem", "Home"))
)
.Events(events => events.DataBound("dataBound"))
)
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().Grid<RMS.Admin.Metadata>()
.Name("grid_#=ResourceId#")
.Columns(columns =>
{
columns.Bound(o => o.MetaDataName);
columns.Bound(o => o.MetaDataDescription);
columns.Bound(o => o.LanguageCode);
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(172).Title("Edit/Delete");
})
.HtmlAttributes(new { style = "height:500px" })
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model => model.Id(s => s.MetaDataId))
.Read(read => read.Action("GetMetaDataByResourceId", "Home", new { id = "#=ResourceId#" }))
.Create(update => update.Action("CreateMetaData", "Home", new { id = "#=ResourceId#" }))
.Update(update => update.Action("SaveSystem", "Home"))
.Destroy(destroy => destroy.Action("RemoveSystem", "Home"))
)
.Scrollable()
.Sortable()
.ToClientTemplate()
)
So when i add clienttemplate to resourcetype on the main grid everything works as it should but when i press create button is tells me
"Uncaught ReferenceError: ResourceType is not defined "
If i take clienttemplate away the dropdownlist in the grid wont work.
I have the next Kendo Grid, all the events in the models take place, no problem!.
The problem is when I change a value in the grid, it not refresh again.
How I can fix this, or how I can get the event occurring when I do changes on the grid, to manage the grid refresh with JQuery.
#(Html.Kendo().Grid<Corporativo.Model.SolProdVM>()
.Name("SolicitudesProducto")
.Columns(columns =>
{
columns.Bound(e => e.Id_Producto).Width(80).Title("Código");
columns.Bound(e => e.DescProducto).Width(40).Groupable(false).Title("Producto");
columns.Bound(e => e.UM).Width(40).Groupable(false).Title("UM");
columns.Bound(e => e.Precio).Width(40).Groupable(false).Title("Precio");
columns.Bound(e => e.Cantidad).Width(40).Groupable(false).Title("Cantidad");
columns.Bound(e => e.Importe).Width(40).Groupable(false).Title("Importe");
columns.Command(command => command.Custom("Eliminar").Click("elimar_de_solicitud")).Width(25);
})
.Sortable()
.ToolBar(toolBar =>
{
toolBar.Save().Text("Guardar cambios");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Filterable()
.Pageable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Model(model => {
model.Id(p => p.Id_Solicitud);
model.Id(p => p.Id_Producto);
model.Field(p => p.Desc_Producto).Editable(false);
model.Field(p => p.UM).Editable(false);
model.Field(p => p.Precio).Editable(false);
model.Field(p => p.Cantidad);
model.Field(p => p.Importe).Editable(false);
})
.Read(read => read.Action("GetAllSolProdJSON", "ProductRequest", new { Id_Solicitud = #Model.Id_Solicitud }))
.Update(update => update.Action("ActualizarSolProd", "ProductRequest").Type(HttpVerbs.Post))
.Destroy(destroy => destroy.Action("EliminarSolProd", "ProductRequest").Type(HttpVerbs.Post))
)
)
There is an Events Method you can call.
#(Html.Kendo().Grid<Model_MVC.Models.OrderGridViewModel>()
.Name("ProposalGrid")
.HtmlAttributes(new { style = "font-size:14px;line-height:2em;width:80%;margin-left:190px;" })
.Columns(columns =>
{
//columns
})
.
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Orders_Read", "Orders"))
.Events(x => x.Change("JSFunction") )
.Model(model =>
{
model.Id(i => i.OrderId);
model.Field(x => x.OrderId).Editable(false);
})
.PageSize(15)
)
.Pageable()
)
I have use Kendo version 2012.03.1114 and below mention code to add value to model and work fine but when I update the kendo varsion to 2013.3.1119 it will give a error
(TypeError: $(...).data(...).kendoGrid.editable is undefined)
any workaround please?
var model = $('#grid').data().kendoGrid.editable.options.model;
model.set('Name', getNames());
#(Html.Kendo().Grid<ABC.Domain.Entities.user>()
.Name("Grid")
.Columns(columns => {
columns.Command(command => { command.Edit(); }).Width(80);
columns.Bound(u => u.Name).Title("Name").Width(150);
columns.Bound(u => u.Status).Title("Status").Width(70);
columns.Bound(u => u.Address).Title("Address").Width(100); })
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("userEdit")) .Events(events => events.DataBound("onDataBound").Edit("onEdit"))
.Pageable(paging => paging.PageSizes(new int[] { 5, 10, 20, 50 })
.Refresh(true))
.Sortable() .ToolBar(toolbar => toolbar.Create())
.Resizable(resize => resize.Columns(true))
.Scrollable()
.DataSource(dataSource => dataSource .Ajax() .Model(model => { model.Id(p => p.userKey); }) .PageSize(5) .Events(events => events.Error("error_handler"))
.Read(read => read.Action("user_Read", "User"))
.Update(update => update.Action("User_Update", "User"))
.Create(create => create.Action("User_Create", "User")) ) )
I have a grid which has a child/sub Grid. It works fine, I can add and remove. However, when I attempt to run the command.destroy, should I press Cancel on the confirmation, it fires again (so I have to press Cancel again). If I choose Confirm, it doesn't popup again and does delete it on first try.
I am unsure whats causing this and I don't think it's my CSHTML but just need a second opinion.
#(Html.Kendo().Grid<ModelA>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.ID).Width(50);
columns.Bound(o => o.Name).Width(300);
columns.Bound(o => o.UpdateUser).Width(100);
columns.Bound(o => o.UpdateDate).Format("{0:d}").Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create())
.ClientDetailTemplateId("adTemplate")
.Pageable()
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("RoleTemplate"))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("RoleRead", "Role"))
.Update(update => update.Action("RoleUpdate", "Role"))
.Create(create => create.Action("RoleCreate", "Role"))
.Destroy(destroy => destroy.Action("RoleRemove", "Role"))
.PageSize(10)
.Model(model =>
{
model.Id(c => c.ID);
model.Field(c => c.UpdateUser).Editable(false).DefaultValue(Context.User.Identity.Name);
model.Field(c => c.UpdateDate).Editable(false).DefaultValue(DateTime.Now);
})
)
.Sortable()
.Filterable()
)
<script id="adTemplate" type="text/kendo-tmpl">
#(Html.Kendo().Grid<ModelAChild>()
.Name("Roles_#=ID#")
.Columns(columns =>
{
columns.Bound(s => s.ActiveDirectoryGroup).Width(500);
columns.Command(command => { command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("RoleSecurityTemplate"))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("RoleReadSecurity", "Role", new { roleID = "#=ID#" }))
.Create(create => create.Action("RoleAddSecurity", "Role", new { roleID = "#=ID#" }))
.Destroy(destroy => destroy.Action("RoleRemoveSecurity", "Role", new { roleID = "#=ID#" }))
.Model(model =>
{
model.Id(s => s.ID);
model.Field(s => s.UpdateUser).Editable(false).DefaultValue(Context.User.Identity.Name);
model.Field(s => s.UpdateDate).Editable(false).DefaultValue(DateTime.Now);
})
)
.Pageable()
.Sortable()
.ToClientTemplate())
</script>
Update your version to the latest one. This was fixed some releases ago.