Hello All!
I have setup a page that uses the Kendo UI Grid (code attached below). Everything seems to be working fine with the exception of filtering. I've looked at the documentation and browsed through the forums, but must have completely missed the answer. Can anyone take a look and offer any help? Thanks for your time in advance!
Brun
chtml code
controller code
I have setup a page that uses the Kendo UI Grid (code attached below). Everything seems to be working fine with the exception of filtering. I've looked at the documentation and browsed through the forums, but must have completely missed the answer. Can anyone take a look and offer any help? Thanks for your time in advance!
Brun
chtml code
01.
@using (Ajax.BeginForm("AddCurriculum", "Home", new { @personID = ViewBag.UserID }, new AjaxOptions
02.
{
03.
HttpMethod = "Post",
04.
InsertionMode = InsertionMode.Replace,
05.
UpdateTargetId = "PersonCurriculum",
06.
OnSuccess = "resetAddCurriculum",
07.
OnComplete = "closeAddCurriculum"
08.
}))
09.
{
10.
<!-- Modal -->
11.
<
div
class
=
"modal fade"
id
=
"addCurriculum"
tabindex
=
"-1"
role
=
"dialog"
aria-labelledby
=
"myModalLabel"
aria-hidden
=
"true"
data-backdrop
=
"static"
>
12.
<
div
class
=
"modal-dialog"
style
=
"width: 1500px; height: 600px;"
>
13.
<
div
class
=
"modal-content"
>
14.
<
div
class
=
"modal-header"
>
15.
<
button
type
=
"button"
class
=
"close"
data-dismiss
=
"modal"
aria-hidden
=
"true"
>×</
button
>
16.
<
h4
class
=
"modal-title"
>Add Curriculum</
h4
>
17.
</
div
>
18.
<
div
class
=
"modal-body"
>
19.
@(Html.Kendo().Grid<
NCHTraining.Models.CourseSchedule
>()
20.
.Name("courseSchedules")
21.
.Columns(columns =>
22.
{
23.
columns.Bound(c => c.ID)
24.
.ClientTemplate("<
button
name=\"btnAddCurriculum\" type=\"submit\" class=\"btn btn-primary\" value=\"#=ID#\">Add</
button
>")
25.
.HtmlAttributes(new { style = "text-align:center; width:100px;" })
26.
.Title("")
27.
.Sortable(false)
28.
.Filterable(false);
29.
columns.Bound(c => c.Course.Name).Filterable(true);
30.
columns.Bound(c => c.StartDateTime)
31.
.Format("{0: MM/dd/yyyy}")
32.
.HeaderHtmlAttributes(new { style = "text-align:center;" })
33.
.HtmlAttributes(new { style = "text-align:center; width:100px;" })
34.
.Title("Start Date")
35.
.Filterable(false);
36.
columns.Bound(c => c.StartDateTime)
37.
.Format("{0: hh:mm:ss tt}")
38.
.HeaderHtmlAttributes(new { style = "text-align:center;" })
39.
.HtmlAttributes(new { style = "text-align:center; width:100px;" })
40.
.Title("Start Time")
41.
.Sortable(false)
42.
.Filterable(false);
43.
columns.Bound(c => c.EndDateTime)
44.
.Format("{0: hh:mm:ss tt}")
45.
.HeaderHtmlAttributes(new { style = "text-align:center;" })
46.
.HtmlAttributes(new { style = "text-align:center; width:100px;" })
47.
.Title("End Time")
48.
.Sortable(false)
49.
.Filterable(false);
50.
columns.Bound(c => c.AvailableSeats)
51.
.HeaderHtmlAttributes(new { style = "text-align:center;" })
52.
.HtmlAttributes(new { style = "text-align:center; width:100px;" })
53.
.Title("Seats Remaining")
54.
.Filterable(false);
55.
})
56.
.Pageable()
57.
.Sortable()
58.
.Filterable()
59.
.DataSource(dataSource => dataSource
60.
.Ajax()
61.
.PageSize(10)
62.
.Sort(sort => sort.Add("StartDateTime").Ascending())
63.
.Read(read => read.Action("GetCourseSchedules", "Home", new { @personID = ViewBag.UserID }))
64.
)
65.
)
66.
</
div
>
67.
<
div
class
=
"modal-footer"
>
68.
<
button
id
=
"btnCloseAddCurriculum"
type
=
"button"
class
=
"btn btn-default"
data-dismiss
=
"modal"
>Cancel</
button
>
69.
</
div
>
70.
</
div
>
71.
<!-- /.modal-content -->
72.
</
div
>
73.
<!-- /.modal-dialog -->
74.
</
div
>
75.
<!-- /.modal -->
76.
}
77.
78.
<
script
>
79.
function resetAddCurriculum(context) {
80.
// Get grid, set to page 1, and refresh data
81.
var grid = $('#courseSchedules').data('kendoGrid');
82.
grid.dataSource.page(1);
83.
grid.dataSource.read();
84.
}
85.
86.
function closeAddCurriculum(context) {
87.
// Close modal
88.
$('#btnCloseAddCurriculum').click();
89.
}
90.
</
script
>
controller code
01.
public
JsonResult GetCourseSchedules([DataSourceRequest]DataSourceRequest request,
int
personID)
02.
{
03.
using
(NCHTrainingDataContext db =
new
NCHTrainingDataContext())
04.
{
05.
// Get the persons curriculum
06.
var personCurriculumIDs = GetPersonCurriculum(personID).Select(pc => pc.CourseScheduleID);
07.
08.
// Get the list of available cousre schedules
09.
IQueryable<CourseSchedule> courseSchedules = db.CourseSchedule.Where(c => c.StartDateTime > DateTime.Now
10.
&& c.AvailableSeats > 0
11.
&& !personCurriculumIDs.Contains(c.ID))
12.
.Include(c => c.Course)
13.
.Include(c => c.Course.CourseLocation)
14.
.Include(c => c.Course.CourseType);
15.
16.
return
Json(courseSchedules.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
17.
}
18.
}