Hello,
I have been evaluating the grid and I cant seem to get the Create method to work , no reaction on the grid. The edit works fine, which is using the custom template. The grid is configured to work in the popup edit mode.
Perhaps I am missing something small, but even the sample project that i downloaded from the code library (foreignkeydemo) doesnt work.
I have followed the examples in the documentation to no avail.
Here is the code below, i would appreciate if anyone can point me in the right direction or perhaps some documentation that i might have missed.
Thanks in advance.
Max.
Index.cshtml.
@using PMTrack
<script type="text/kendo" id="memberTemplate">
<ul>
#for(var i=0; i<data.length; i++){#
<li> #:data[i].Firstname +" "+ data[i].Lastname #</li>
#}#
</ul>
</script>
<script type="text/javascript">
var memberTemplate = kendo.template($("#memberTemplate").html(), {useWithBlock:false})
</script>
@(Html.Kendo().Grid<Project>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Width(5).Title("#").Filterable(false);
columns.Bound(p => p.Name).Width(60).Title("Project name");
columns.Bound(p => p.StartDate).Width(50).Filterable(true).Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.PlannedEndDate).Width(50).Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.Status).Width(20);
columns.Bound(p => p.Members).ClientTemplate("#=memberTemplate(Members)#").Width(100);
columns.Bound(p => p.Owner.Firstname).ClientTemplate("#=Owner?Owner.Firstname:''#").Title("Owner").Width(50);
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(40);
} )
.ToolBar(toolbar => toolbar.Create().Text("New Project"))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ProjectEditorTemplate"))
.Pageable()
.Sortable()
.HtmlAttributes( new { style="width:900px"})
.Filterable()
.DataSource(ds => ds.Ajax().Events(e => e.Error("onError"))
.PageSize(20)
.Model(model => model.Id(p =>p.Id))
.Read(read => read.Action("Read", "Home"))
.Update(update=> update.Action("Update", "Home"))
.Destroy(destroy => destroy.Action("Delete", "Home"))
.Create(create => create.Action("Insert", "Home").Type(HttpVerbs.Post))
))
<script type="text/javascript">
function onError(e) {
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>
<script>
$(document).ready(function () {
kendo.culture("en-GB");
});
</script>
The Controller :
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
{
var ps = new ProjectService();
return Json(ps.Read().ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update([DataSourceRequest] DataSourceRequest request, Project project)
{
if (project != null && ModelState.IsValid)
{
var ps = new ProjectService();
ps.Update(project);
}
return Json(new[] { project }.ToDataSourceResult(request, ModelState));
}
public ActionResult Delete([DataSourceRequest] DataSourceRequest request, Project project)
{
if (project != null)
{
var ps = new ProjectService();
ps.Delete(project);
}
return Json(new[] { project }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Insert([DataSourceRequest] DataSourceRequest request, Project project)
{
if (project != null && ModelState.IsValid)
{
var ps = new ProjectService();
ps.Create(project);
}
return Json(new[] { project }.ToDataSourceResult(request, ModelState));
}
public ActionResult Index()
{
var ms = new MemberService();
var members = ms.GetAll();
var status = new List<string>
{
"Development",
"Validation"
};
ViewData["status"] = status;
ViewData["owners"] = members;
ViewData["members"] = members;
return View();
}
I have been evaluating the grid and I cant seem to get the Create method to work , no reaction on the grid. The edit works fine, which is using the custom template. The grid is configured to work in the popup edit mode.
Perhaps I am missing something small, but even the sample project that i downloaded from the code library (foreignkeydemo) doesnt work.
I have followed the examples in the documentation to no avail.
Here is the code below, i would appreciate if anyone can point me in the right direction or perhaps some documentation that i might have missed.
Thanks in advance.
Max.
Index.cshtml.
@using PMTrack
<script type="text/kendo" id="memberTemplate">
<ul>
#for(var i=0; i<data.length; i++){#
<li> #:data[i].Firstname +" "+ data[i].Lastname #</li>
#}#
</ul>
</script>
<script type="text/javascript">
var memberTemplate = kendo.template($("#memberTemplate").html(), {useWithBlock:false})
</script>
@(Html.Kendo().Grid<Project>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Width(5).Title("#").Filterable(false);
columns.Bound(p => p.Name).Width(60).Title("Project name");
columns.Bound(p => p.StartDate).Width(50).Filterable(true).Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.PlannedEndDate).Width(50).Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.Status).Width(20);
columns.Bound(p => p.Members).ClientTemplate("#=memberTemplate(Members)#").Width(100);
columns.Bound(p => p.Owner.Firstname).ClientTemplate("#=Owner?Owner.Firstname:''#").Title("Owner").Width(50);
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(40);
} )
.ToolBar(toolbar => toolbar.Create().Text("New Project"))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ProjectEditorTemplate"))
.Pageable()
.Sortable()
.HtmlAttributes( new { style="width:900px"})
.Filterable()
.DataSource(ds => ds.Ajax().Events(e => e.Error("onError"))
.PageSize(20)
.Model(model => model.Id(p =>p.Id))
.Read(read => read.Action("Read", "Home"))
.Update(update=> update.Action("Update", "Home"))
.Destroy(destroy => destroy.Action("Delete", "Home"))
.Create(create => create.Action("Insert", "Home").Type(HttpVerbs.Post))
))
<script type="text/javascript">
function onError(e) {
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>
<script>
$(document).ready(function () {
kendo.culture("en-GB");
});
</script>
The Controller :
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
{
var ps = new ProjectService();
return Json(ps.Read().ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update([DataSourceRequest] DataSourceRequest request, Project project)
{
if (project != null && ModelState.IsValid)
{
var ps = new ProjectService();
ps.Update(project);
}
return Json(new[] { project }.ToDataSourceResult(request, ModelState));
}
public ActionResult Delete([DataSourceRequest] DataSourceRequest request, Project project)
{
if (project != null)
{
var ps = new ProjectService();
ps.Delete(project);
}
return Json(new[] { project }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Insert([DataSourceRequest] DataSourceRequest request, Project project)
{
if (project != null && ModelState.IsValid)
{
var ps = new ProjectService();
ps.Create(project);
}
return Json(new[] { project }.ToDataSourceResult(request, ModelState));
}
public ActionResult Index()
{
var ms = new MemberService();
var members = ms.GetAll();
var status = new List<string>
{
"Development",
"Validation"
};
ViewData["status"] = status;
ViewData["owners"] = members;
ViewData["members"] = members;
return View();
}