Hi,
I have kendogrid with list of dropdown filters.
I am stuggling to call the javascript to load the dropdown in the ready function.
Basically I am not able to find the dropdown element in the grid so that I can call the javasript to load the dropdown again.
View Code:
@using (Html.BeginForm("ReplaySelectedInboundMessages", "Home"))
{
<div id="gridContent">
<h1></h1>
@(Html.Kendo().Grid<ViaPath.MessageReplay.MvcApp.Models.LogModel>(Model)
.Name("gridTable")
//.EnableCustomBinding(true)
.HtmlAttributes(new {style = "font-family: verdana,arial,sans-serif; font-size: 11px;color: #333333;border-color: #999999;"})
.Columns(columns =>
{
columns.Template(@<text><input class="box" id="assignChkBx" name="assignChkBx" type="checkbox" value="@item.LogID"/></text>).HeaderTemplate(@<text><input class="selectAll" type="checkbox" id="allBox" onclick="toggleSelection()"/></text>).Width(20);
//columns.Template(p => { }).ClientTemplate("<input type='checkbox' #= CheckSelect ? checked='checked':'' # class='chkbx' />");
columns.Bound(p => p.LogID).Template(p => Html.ActionLink(((string)p.LogID), "MessageDetails", new { logid = p.LogID })).Width(200);
columns.Bound(p => p.ReceivePortName).Width(100).Filterable(ft => ft.UI("ReceivePortsFilter")); //.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(p => p.SendPortName).Width(100).Filterable(ft => ft.UI("SendPortsFilter"));
columns.Bound(p => p.loggedDate).Format("{0:MM/dd/yyyy hh:mm tt}").Filterable(f => f.UI("DateTimeFilter").Extra(true)).Width(100);
columns.Bound(p => p.ControlID).Width(100);
columns.Bound(p => p.SenderID).Width(100).Filterable(ft => ft.UI("SenderIDFilter"));
columns.Bound(p => p.ReceiverID).Width(100).Filterable(ft => ft.UI("ReceiverIDFilter"));
columns.Bound(p => p.InterchangeID).Width(100);
columns.Bound(p => p.ReplayedCount).Width(100);
columns.Bound(p => p.RetryCount).Width(100);
columns.Bound(p => p.AckCode).Width(20);
})
// .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Filterable()
.Pageable(page => page.PageSizes(new int[]{10,25,50,100}).Enabled(true))
.Sortable()
.Scrollable(src => src.Height("auto"))
.Resizable(resize => resize.Columns(true))
)
<br />
<br />
<input type="Submit" name="btnReplayMessage" value="Replay" title="Replay Message" \>
</div>
<script type="text/javascript">
function ReceivePortsFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_ReceivePorts")"
}
},
optionLabel: "--Select Value--"
});
}
function SendPortsFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_SendPorts")"
}
},
optionLabel: "--Select Value--"
});
}
function ReceiverIDFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_ReceiverID")"
}
},
optionLabel: "--Select Value--"
});
}
function SenderIDFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_SenderID")"
}
},
optionLabel: "--Select Value--"
});
}
function DateTimeFilter(control) {
$(control).kendoDateTimePicker();
}
$(document).ready(function () {
var grid = $("#gridTable").data("kendoGrid");
var dropdown = grid.pager.element
.find(".k-pager-sizes [data-role=dropdownlist]")
.data("kendoDropDownList");
var item = {};
item[dropdown.options.dataTextField] = "All";
item[dropdown.options.dataValueField] = 1000000;
dropdown.dataSource.add(item);
dropdown.bind("change", function (e) {
if (this.text() == "All") {
grid.one("dataBound", function () {
setTimeout(function () {
dropdown.span.text("All");
});
});
}
});
});
</script>
}
Controller Code:
public ActionResult AllMessages([DataSourceRequest(Prefix = "gridTable")] DataSourceRequest request)
{
//var filterCollection = KendoGridFilterCollection.BuildCollection(Request);
List<LogModel> logs = null;
if (request.Filters == null)
logs = this.GetAllMessages().Where(x => x.loggedDate >= DateTime.Today.AddDays(-7)).ToList();
else
logs = this.GetAllMessages();
Session.Clear();
Session["ReceivePortsList"] = logs.OrderBy(e => e.ReceivePortName).Select(a => a.ReceivePortName).Distinct();
Session["SendPortName"] = logs.OrderBy(e => e.SendPortName).Select(a => a.SendPortName).Distinct();
Session["SenderID"] = logs.OrderBy(e => e.SenderID).Select(e => e.SenderID).Distinct();
Session["ReceiverID"] = logs.OrderBy(e => e.ReceiverID).Select(e => e.ReceiverID).Distinct();
return View(logs);
}
public ActionResult FilterMenuCustomization_ReceivePorts()
{
//List<LogModel> logs = this.GetAllMessages();
//return Json(logs.Select(e => e.ReceivePortName).Distinct(), JsonRequestBehavior.AllowGet);
return Json(Session["ReceivePortsList"], JsonRequestBehavior.AllowGet);
}
I have kendogrid with list of dropdown filters.
I am stuggling to call the javascript to load the dropdown in the ready function.
Basically I am not able to find the dropdown element in the grid so that I can call the javasript to load the dropdown again.
View Code:
@using (Html.BeginForm("ReplaySelectedInboundMessages", "Home"))
{
<div id="gridContent">
<h1></h1>
@(Html.Kendo().Grid<ViaPath.MessageReplay.MvcApp.Models.LogModel>(Model)
.Name("gridTable")
//.EnableCustomBinding(true)
.HtmlAttributes(new {style = "font-family: verdana,arial,sans-serif; font-size: 11px;color: #333333;border-color: #999999;"})
.Columns(columns =>
{
columns.Template(@<text><input class="box" id="assignChkBx" name="assignChkBx" type="checkbox" value="@item.LogID"/></text>).HeaderTemplate(@<text><input class="selectAll" type="checkbox" id="allBox" onclick="toggleSelection()"/></text>).Width(20);
//columns.Template(p => { }).ClientTemplate("<input type='checkbox' #= CheckSelect ? checked='checked':'' # class='chkbx' />");
columns.Bound(p => p.LogID).Template(p => Html.ActionLink(((string)p.LogID), "MessageDetails", new { logid = p.LogID })).Width(200);
columns.Bound(p => p.ReceivePortName).Width(100).Filterable(ft => ft.UI("ReceivePortsFilter")); //.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(p => p.SendPortName).Width(100).Filterable(ft => ft.UI("SendPortsFilter"));
columns.Bound(p => p.loggedDate).Format("{0:MM/dd/yyyy hh:mm tt}").Filterable(f => f.UI("DateTimeFilter").Extra(true)).Width(100);
columns.Bound(p => p.ControlID).Width(100);
columns.Bound(p => p.SenderID).Width(100).Filterable(ft => ft.UI("SenderIDFilter"));
columns.Bound(p => p.ReceiverID).Width(100).Filterable(ft => ft.UI("ReceiverIDFilter"));
columns.Bound(p => p.InterchangeID).Width(100);
columns.Bound(p => p.ReplayedCount).Width(100);
columns.Bound(p => p.RetryCount).Width(100);
columns.Bound(p => p.AckCode).Width(20);
})
// .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Filterable()
.Pageable(page => page.PageSizes(new int[]{10,25,50,100}).Enabled(true))
.Sortable()
.Scrollable(src => src.Height("auto"))
.Resizable(resize => resize.Columns(true))
)
<br />
<br />
<input type="Submit" name="btnReplayMessage" value="Replay" title="Replay Message" \>
</div>
<script type="text/javascript">
function ReceivePortsFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_ReceivePorts")"
}
},
optionLabel: "--Select Value--"
});
}
function SendPortsFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_SendPorts")"
}
},
optionLabel: "--Select Value--"
});
}
function ReceiverIDFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_ReceiverID")"
}
},
optionLabel: "--Select Value--"
});
}
function SenderIDFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read: "@Url.Action("FilterMenuCustomization_SenderID")"
}
},
optionLabel: "--Select Value--"
});
}
function DateTimeFilter(control) {
$(control).kendoDateTimePicker();
}
$(document).ready(function () {
var grid = $("#gridTable").data("kendoGrid");
var dropdown = grid.pager.element
.find(".k-pager-sizes [data-role=dropdownlist]")
.data("kendoDropDownList");
var item = {};
item[dropdown.options.dataTextField] = "All";
item[dropdown.options.dataValueField] = 1000000;
dropdown.dataSource.add(item);
dropdown.bind("change", function (e) {
if (this.text() == "All") {
grid.one("dataBound", function () {
setTimeout(function () {
dropdown.span.text("All");
});
});
}
});
});
</script>
}
Controller Code:
public ActionResult AllMessages([DataSourceRequest(Prefix = "gridTable")] DataSourceRequest request)
{
//var filterCollection = KendoGridFilterCollection.BuildCollection(Request);
List<LogModel> logs = null;
if (request.Filters == null)
logs = this.GetAllMessages().Where(x => x.loggedDate >= DateTime.Today.AddDays(-7)).ToList();
else
logs = this.GetAllMessages();
Session.Clear();
Session["ReceivePortsList"] = logs.OrderBy(e => e.ReceivePortName).Select(a => a.ReceivePortName).Distinct();
Session["SendPortName"] = logs.OrderBy(e => e.SendPortName).Select(a => a.SendPortName).Distinct();
Session["SenderID"] = logs.OrderBy(e => e.SenderID).Select(e => e.SenderID).Distinct();
Session["ReceiverID"] = logs.OrderBy(e => e.ReceiverID).Select(e => e.ReceiverID).Distinct();
return View(logs);
}
public ActionResult FilterMenuCustomization_ReceivePorts()
{
//List<LogModel> logs = this.GetAllMessages();
//return Json(logs.Select(e => e.ReceivePortName).Distinct(), JsonRequestBehavior.AllowGet);
return Json(Session["ReceivePortsList"], JsonRequestBehavior.AllowGet);
}