Hi there,
I am trying to filter my grid using 2 dropdownlists in the toolbar template section of the grid. I have been able to copy the example http://demos.telerik.com/aspnet-mvc/grid/toolbar-template which works absolutely fine and I have also been able to replicate the code for another dropdownlist but they are performing separate filtering.
I would like to be able to filter by one dropdownlist and then filter the results of that filter by the next dropdownlist.
the grid code I currently have is:
.ToolBar(toolbar =>
{
toolbar.Template(@<text>
<div class="toolbar">
<label class="site-label" for="site">Show reports by site:</label>
@(Html.Kendo().DropDownList()
.Name("sites")
.OptionLabel("All")
.DataTextField("SiteName")
.DataValueField("ClientSiteId")
.AutoBind(false)
.Events(e => e.Change("sitesChange"))
.DataSource(ds =>
{
ds.Read("ToolbarTemplate_Sites", "Report");
}))
</div>
<div class="new-toolbar">
<label class="type-label" for="type">Show reports by type:</label>
@(Html.Kendo().DropDownList()
.Name("type")
.OptionLabel("All")
.DataTextField("StockTypeName")
.DataValueField("StockTypeId")
.AutoBind(false)
.Events(e => e.Change("typesChange"))
.DataSource(ds =>
{
ds.Read("ToolbarTemplate_Types", "Report");
}))
</div>
</text>);
})
// the Script
function sitesChange() {
var value = this.value(),
grid = $("#grid").data("kendoGrid");
if (value) {
grid.dataSource.filter({ field: "ClientSiteId", operator: "eq", value: parseInt(value) });
} else {
grid.dataSource.filter({});
}
}
function typesChange() {
var value = this.value(),
grid = $("#grid").data("kendoGrid");
if (value) {
grid.dataSource.filter({ field: "StockTypeId", operator: "eq", value: parseInt(value) });
} else {
grid.dataSource.filter({});
}
}
Any help would be greatly appreciated.
Regards