Hi there,
I set up my grid to use multiple grid filters which are combo boxes. These filters allow you to refine your displayed data however there is a slight problem when using them. Initially they work fine but when you use them in conjunction with one another you get an error
System.FormatException: String was not recognized as a valid DateTime.
I made 4 filters, 3 of them are string values and 1 of them is a datetime (see below).
@(Html.Kendo().ComboBox()
.Name("periods")
.Suggest(true)
.Filter("contains")
.DataTextField("Text")
.DataValueField("Value")
.Events(e => e.Change("filterChange"))
.BindTo(new List<
SelectListItem
>() {
new SelectListItem() {
Text = "All",
Value = "30000"
},
new SelectListItem() {
Text = "3 Months",
Value = "90"
},
new SelectListItem() {
Text = "21 Days",
Value = "21"
}}))
@(Html.Kendo().ComboBox()
.Name("locations")
.Placeholder("-- Filter Region --")
.Suggest(true)
.Filter("contains")
.DataTextField("Text")
.DataValueField("Value")
.AutoBind(false)
.Events(e => e.Change("filterChange"))
.BindTo(new List<
SelectListItem
>() {
new SelectListItem() {
Text = "Aberdeen",
Value = "1"
},
new SelectListItem() {
Text = "Norway",
Value = "2"
},
new SelectListItem() {
Text = "Southern Sector",
Value = "3"
},
new SelectListItem() {
Text = "North Sea",
Value = "4"
},
new SelectListItem() {
Text = "Brazil",
Value = "7"
},
new SelectListItem() {
Text = "Other",
Value = "8"
},
new SelectListItem() {
Text = "All",
Value = ""
}}))
@(Html.Kendo().ComboBox()
.Name("owners")
.Placeholder("-- Filter Owner --")
.Suggest(true)
.Filter("contains")
.DataTextField("company_name")
.DataValueField("company_name")
.AutoBind(false)
.Events(e => e.Change("filterChange"))
.DataSource(ds =>
{
ds.Read("toolbar_Owners", "Home");
}))
@(Html.Kendo().ComboBox()
.Name("vessel_types")
.Placeholder("-- Select Type --")
.Suggest(true)
.Filter("contains")
.DataTextField("spot_name")
.DataValueField("spot_name")
.AutoBind(false)
.Events(e => e.Change("filterChange"))
.DataSource(ds =>
{
ds.Read("toolbar_Types", "Home");
}))
If you filter on PERIODS and REGION there is no error at all. If you filter on PERIODS and any other filter the above error regarding datetime is thrown. Here is the javascript that handles the filters:
function filterChange() {
var filters = [];
var grid = $('#Grid').data('kendoGrid');
var ddl_owners = $("#owners").getKendoComboBox().value();
var ddl_region = $("#locations").getKendoComboBox().value();
var ddl_types = $("#vessel_types").getKendoComboBox().value();
var ddl_periods = $("#periods").getKendoComboBox().value();
var value = this.value();
//Convert value of dropdown to int
intDays = parseInt(value),
today = new Date(),
addDays = ddl_periods.value;
today.setDate(today.getDate() + intDays);
today.setHours(0, 0, 0, 0);
if (ddl_owners) {
filters.push(
{
field: "owner_company",
operator: "eq",
value: ddl_owners
}
);
}
if (ddl_region) {
filters.push(
{
field: "current_location_spotlist_id" && "spotlist_id",
operator: "eq",
value: ddl_region
}
);
}
if (ddl_types) {
filters.push(
{
field: "vessel_type",
operator: "eq",
value: ddl_types,
}
);
console.log("Type" + ddl_types);
}
if (ddl_periods) {
filters.push(
{
field: "fixture_stop",
operator: "lte",
value: today
}
);
console.log("Period: " + today);
}
grid.dataSource.filter({
logic: "and",
filters: filters
});
}
I am looking for some help on where I may have gone wrong.
Thanks