I'm working on an application which I have now almost finished but I have one thing that I really need to sort out before I release. I return a dataset of around 600 rows to the grid. I then chose to Edit one of these rows and change the value in a ComboBox Editor template. For example, I might change it from Jan Jones to John Smith.
This all works fine at the database level. However, when I press Update the values displayed in the Display template are still Jan Jones and not John Smith. So far, the only way I've been able to get this to work is by using a dataSource refresh in the onSync event. However, this is taking at least 15 seconds to reload the entire grid.I guess it is returning the entire dataset and not just the currently displayed page.
Presumably, I am doing something wrong somewhere but I am not sure where. Any help would be most useful as I have been scratching my head on this for a while now.
Controller
Grid
Dropdown
This all works fine at the database level. However, when I press Update the values displayed in the Display template are still Jan Jones and not John Smith. So far, the only way I've been able to get this to work is by using a dataSource refresh in the onSync event. However, this is taking at least 15 seconds to reload the entire grid.I guess it is returning the entire dataset and not just the currently displayed page.
Presumably, I am doing something wrong somewhere but I am not sure where. Any help would be most useful as I have been scratching my head on this for a while now.
Controller
01.
public
JsonResult GetTestDetailed([DataSourceRequest] DataSourceRequest request)
02.
{
03.
var testTable = dataAccessLayer.GetDataTable(
"select statement here"
);
//testTable will be about 600 rows
04.
var testDictionary = (from DataRow row
in
testTable.Rows select testTable.Columns.Cast<DataColumn> ().ToDictionary(column => column.ColumnName, column => row[column].ToString())).ToList().AsQueryable();
05.
return
Json(testDictionary.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
06.
}
07.
}
08.
09.
[AcceptVerbs(HttpVerbs.Post)]
10.
public
ActionResult Update([DataSourceRequest] DataSourceRequest request, TestDirectoryDetail testDetail)
11.
{
12.
dataAccessLayer.Update(testDetail);
13.
return
Json(
new
[] { testDetail }.ToDataSourceResult(request, ModelState));
14.
}
Grid
01.
<script type=
"text/javascript"
>
02.
function onSync(e) {
03.
var grid = $(
'#TestGrid'
).data(
'kendoGrid'
);
04.
grid.dataSource.read();
05.
}
06.
</script>
07.
08.
@(Html.Kendo().Grid((IEnumerable<DirectoryDetail>)ViewBag.Details)
09.
.Name(
"TestGrid"
)
10.
.HtmlAttributes(
new
{ style =
"height:850px;"
})
11.
.Editable(editable => editable.Mode(GridEditMode.InLine))
12.
.Events(e => e.SaveChanges(
"onSaveChanges"
))
13.
.Filterable()
14.
.Groupable()
15.
.Pageable()
// Enable pageing
16.
.Scrollable(scr=>scr.Height(
"auto"
))
17.
.Sortable()
// Enable sorting
18.
.DataSource(dataSource => dataSource
19.
.Ajax()
20.
.Events(events => events.Error(
"error_handler"
).Sync(
"onSync"
))
21.
.PageSize(15)
22.
.Model(model =>
23.
{
24.
model.Id(p => p.Id);
25.
})
26.
.Update(update => update.Action(
"Update"
,
"Home"
))
27.
.Read(read => read.Action(
"GetPracticesDetailed"
,
"Home"
))
28.
)
29.
.Columns(columns =>
30.
{
31.
columns.Bound(m => m.PracticeId).Title(
"Id"
);
32.
columns.Bound(m => m.PayManager).Width(150).Title(
"DPM"
).Template(m => m.PayManager).EditorTemplateName(
"PayManagerDropDown"
).ClientTemplate(
"#:PayManager#"
);
33.
columns.Command(command => command.Edit()).Title(
"Actions"
);
34.
})
35.
.Resizable(resize => resize.Columns(
true
)))
Dropdown
01.
@(Html.Kendo().ComboBox()
02.
.Name(
"PayManagerId"
)
03.
.Filter(FilterType.StartsWith)
04.
.HtmlAttributes(
new
{style =
"width:auto;"
})
05.
.Placeholder(
"Type beginning of name to select new pay manager"
)
06.
.DataTextField(
"FullName"
)
07.
.DataValueField(
"userid"
)
08.
.AutoBind(
true
)
09.
.Suggest(
true
)
10.
.DataSource(source => source.Read(read => read.Action(
"GetUsers"
,
"Home"
)).ServerFiltering(
false
)))