This is a migrated thread and some comments may be shown as answers.

Filter DateTime column search with DateTime picker

1 Answer 406 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 26 Jul 2017, 09:18 PM

I have a Kendo MVC Grid that has a column with a DateTime column.    Everything looks good and formats correctly.   When i filter,  it gives me a date picker and a time picker.  When i remove the DateTimeFilter Template below and use template contains,  it will give me a Date picker (which i want),  but still wants to filter by the date and time..     Is there a way i can have the date and time all as the same field,  but only filter with a Date picker.?     Example:  i use the Date picker to pick 07/24/2017 and it filter everything on that date regardless of time..      Or do they need to be completely different fields,  or even concatenated fields in the same column.?

 

the Column data looks as such:  07/24/2017 18:12:00 

columns.Bound(c => c.CreatedDate).Title("Submitted On")

.ClientTemplate("#= kendo.toString(kendo.parseDate(CreatedDate), 'MM/dd/yyyy HH:mm:ss') #")

.Filterable(ftb => ftb.Cell(cell => cell.Template("DateTimeFilter")));

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 28 Jul 2017, 11:39 AM
Hi Richard,

It is possible to achieve filtering by date regardless of time using two DateTime properties in the binding ViewModel, e.g:

public class MyViewModel
{
       public int Id { get; set; }
       public DateTime CreatedDate { get; set; }
       public DateTime CreateDateOnly { get { return (this.CreatedDate.Date); } }
}

CreateDate would contain datetime original data from database. CreateDateOnly would contain date only data calculated from CreateDate.

The column configuration should look like this:

columns.Bound(x => x.CreateDateOnly).ClientTemplate(" #= kendo.toString(CreatedDate,\"dd/MM/yyyy hh:mm:ss\") #");

In other words, the field with the date and time is displayed but the column is filtered by the field that contains only the date.

For convenience I created a simple (filter-date-only.zip) project which illustrates such approach in action.


Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or