Here is a working copy of Kendo DropDownList which will change the value of a Kendo Grid.
My HTML: I've linked the necessary css/js files for kendo and general markup to hook kendo controls.
<link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.rtl.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.silver.min.css" rel="stylesheet" />
<script src="@Url.Content("http://cdn.kendostatic.com/2013.3.1119/js/jquery.min.js")"></script>
<script src="@Url.Content("http://cdn.kendostatic.com/2013.3.1119/js/kendo.all.min.js")"></script>
<script src="@Url.Content("http://cdn.kendostatic.com/2013.3.1119/js/kendo.aspnetmvc.min.js")"></script>
<div>
<label class="control-label" for="shiftName">Shift</label>
<div class="controls">
<input id="ShiftInputs" type="text" style="width: 100%; min-width: 60px; max-width: 230px;" value="" />
</div>
<br />
<div class="box-content">
<label class="control-label" for="shiftName">Operator</label>
<div id="OperatorGrid"></div>
<div class="clearfix"></div>
</div>
</div>
My javascript:
//Initialize Kendo DDL
$(document).ready(function () {
$("#ShiftInputs").kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: ShiftData,
index: 0,
change: onChange
});
//Loading Kendo Grid with all data
$("#OperatorGrid").data("kendoGrid").dataSource.read();
});
//DDL values
var ShiftData = [{ text: "ALL", value: "ALL" }, { text: "DAY", value: "DAY" }, { text: "NIGHT", value: "NIGHT" }];
//DDL change event function, hitting Home controller, function StatusCmbChanged.
function onChange() {
var statusValue = $("#ShiftInputs").val();
$.ajax({
url: 'Home/StatusCmbChanged',
type: "POST",
data: { "statusValue": statusValue },
dataType: "json"
}).done(delayedRefresh());
}
function delayedRefresh() {
window.setTimeout(Refresh, 500);
}
function Refresh() {
$("#RefreshMessage").show("slow").delay(5000).hide("slow");
$("#OperatorGrid").data("kendoGrid").dataSource.read();
}
//Main Kendo Grid
$("#OperatorGrid").kendoGrid({
dataSource: {
transport: {
read: {
url: "Home/GetOperatorData",
type: "POST",
contentType: "application/json",
dataType: "json"
},
update: {
url: "UpdateOperatorData",
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json"
},
parameterMap: function (data, operation) {
if (operation != "read") {
return kendo.stringify(data.models);
}
}
},
serverPaging: false,
pageSize: 10,
schema: {
model: {
id: "ID",
fields: {
ID: { editable: false },
Title: { validation: { required: true } },
Name: { editable: true },
Hours: { editable: true, type: "number", validation: { required: true, min: 0, step: 0.25 } },
Shift: { editable: true },
Comments: { editable: true }
}
}
}
},
pageable: {
refresh: true,
pageSizes: true
},
sortable: true,
autoBind: false,
columns:
[
{ field: "Title", width: 100 },
{ field: "Name", width: 120 },
{ field: "Hours", width: 100 },
{ field: "Shift", width: 100 },
{ field: "Comments", width: 100 },
]
});
My MVC Codes: Controller:
public ActionResult Index()
{
return View();
}
My Data Table for the Grid:
static DataTable GetTable()
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Title", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Hours", typeof(int));
table.Columns.Add("Shift", typeof(string));
table.Columns.Add("Comments", typeof(string));
table.Rows.Add(0, "Mr", "Indocin David", 12, "DAY", "Good sprit");
table.Rows.Add(1, "Mr", "Enebrel Sam", 8, "NIGHT", "");
table.Rows.Add(2, "Dr", "Hydralazine Christoff", 12, "DAY", "");
table.Rows.Add(3, "Mrs", "Combivent Janet", 12, "DAY", "");
table.Rows.Add(4, "Miss", "Dilantin Melanie", 8, "NIGHT", "Lazy");
table.Rows.Add(5, "Mr", "Tim Melanie", 14, "DAY", "");
table.Rows.Add(6, "Mr", "Robin Sriboski", 6, "NIGHT", "");
table.Rows.Add(7, "Mrs", "Anna Frank", 13, "NIGHT", "");
table.Rows.Add(8, "Mr", "Dimitri Petrovich", 9, "DAY", "Hard worker");
table.Rows.Add(9, "Mr", "Roberto Carlos", 7, "NIGHT", "");
table.Rows.Add(10, "Mrs", "Stepheny Abraham Lincoln", 13, "DAY", "");
return table;
}
My Kendo Grid Read:
[HttpPost]
public ContentResult GetOperatorData([DataSourceRequest]DataSourceRequest request)
{
string OperatorJsonData = "";
DataTable table = GetTable();
string Shift = Session["CurrentShift"] as string;
if (!string.IsNullOrEmpty(Shift) && (Shift == "DAY" || Shift == "NIGHT"))
{
OperatorJsonData = JsonConvert.SerializeObject(from myRow in table.AsEnumerable()
where myRow.Field<string>("Shift") == Shift
select new
{
ID = myRow.Field<int>("ID"),
Title = myRow.Field<string>("Title"),
Name = myRow.Field<string>("Name"),
Hours = myRow.Field<int>("Hours"),
Shift = myRow.Field<string>("Shift"),
Comments = myRow.Field<string>("Comments")
});
}
else
{
OperatorJsonData = JsonConvert.SerializeObject(table);
}
return new ContentResult { Content = OperatorJsonData, ContentType = "application/json", ContentEncoding = Encoding.UTF8 };
}
My Kendo DropDownList onChange Ajax call hit point:
[HttpPost]
public void StatusCmbChanged(string statusValue)
{
if (!string.IsNullOrEmpty(statusValue))
{
Session.Remove("CurrentShift");
Session["CurrentShift"] = statusValue;
}
}
@marlonies hope this will help you.