This question is locked. New answers and comments are not allowed.
I have followed the filtering example provided here as the basis for creating a search form above a Telerik MVC grid.
I have the basics working correctly, but have run into a little trouble that I can't figure out how to get around.
In the demo, the startsWith textbox is always given a default value on initial load of the page which drives the filter in the grid definition as follows:
As it is a string search using StartsWith, you can easily remove the default values in your demo, by making them empty strings, which essentially means the every record matches StartsWith("").
The problem I have is trying to add a Date filter. I have a Telerick DatePicker, I have my .Filterable setup with a IsEqualTo, but I cannot for the life of me figure out how to set it as "blank" date.
Here is my filter for Date:
My text in bold converts a default date which is set in my Controller as:
Basically, i do not want the DateOfBirth filter to be used until my user has selected a value from the DatePicker and click search.
Also, doing this forces the default value to be displayed in the DatePicker itself.
Help!!!
UPDATE:
So I came up with a workaround.
1) Default value being selected in the DatePicker - I've gotten around that with a little piece of JQuery on document ready that strips out the value.
2) In my query code, I check for the default value I'm setting, and if it matches then I do not filter.
So, I have gotten around the issue, but it does feel very "hacky". Maybe I am doing something wrong in my setup? Hopefully a Telerik guy can confirm.
I have the basics working correctly, but have run into a little trouble that I can't figure out how to get around.
In the demo, the startsWith textbox is always given a default value on initial load of the page which drives the filter in the grid definition as follows:
.Filterable(filtering => filtering.Filters(filters =>{filters.Add(o => o.ContactName).StartsWith("Paul").And().EndsWith("Wilson");}))
As it is a string search using StartsWith, you can easily remove the default values in your demo, by making them empty strings, which essentially means the every record matches StartsWith("").
The problem I have is trying to add a Date filter. I have a Telerick DatePicker, I have my .Filterable setup with a IsEqualTo, but I cannot for the life of me figure out how to set it as "blank" date.
Here is my filter for Date:
.Filterable(filtering => filtering.Filters(filters => filters .Add(o => o.DateOfBirth).IsEqualTo(DateTime.Parse(ViewData["DateOfBirth"].ToString())) ))My text in bold converts a default date which is set in my Controller as:
ViewData["DateOfBirth"] = "1/1/1800"Basically, i do not want the DateOfBirth filter to be used until my user has selected a value from the DatePicker and click search.
Also, doing this forces the default value to be displayed in the DatePicker itself.
Help!!!
UPDATE:
So I came up with a workaround.
1) Default value being selected in the DatePicker - I've gotten around that with a little piece of JQuery on document ready that strips out the value.
2) In my query code, I check for the default value I'm setting, and if it matches then I do not filter.
So, I have gotten around the issue, but it does feel very "hacky". Maybe I am doing something wrong in my setup? Hopefully a Telerik guy can confirm.