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

Grid filter dateTime independent of time

12 Answers 408 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 30 Jan 2015, 10:13 PM
Hi, I am converting a page from webforms and used the Telerik for AJAX RadGrid control originally which provided filtering by date only if specified for dateTime values.  Is this Telerik product lacking this feature?

12 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 03 Feb 2015, 04:06 PM

Hello Bob,

It depends on if you want to show the time part or not. If not then you can use schema.parse to strip the time part from the object, so you can filter by date only like this:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.parse

Or you can implement serverFiltering and handle the filtering on the server based on your specific requirements.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bob
Top achievements
Rank 1
answered on 03 Feb 2015, 04:14 PM
I want to display date & time, sort by date & time, and filter by date only.  I also want all paging, sorting, and filtering done on client.  Our compromise is to not sort on datetime but only by the date part.  This allows us to filter by date and display datetime. 

Basically, we want to stay with Telerik, but many of the features in the Telerik WebForms controls aren't ported over to Kendo.  So users lose features or we come up with hacky work-arounds in many instances.

columns.Bound(m => m.DateCreatedDate).Template(@<text></text>).Title("Date Created").ClientTemplate("#=kendo.toString(DateCreatedDateTime,'M/d/yyyy hh:mm tt')#").Width(170).Format("{0:M/d/yyyy}");
0
Bob
Top achievements
Rank 1
answered on 03 Feb 2015, 04:14 PM
I want to display date & time, sort by date & time, and filter by date only.  I also want all paging, sorting, and filtering done on client.  Our compromise is to not sort on datetime but only by the date part.  This allows us to filter by date and display datetime. 

Basically, we want to stay with Telerik, but many of the features in the Telerik WebForms controls aren't ported over to Kendo.  So users lose features or we come up with hacky work-arounds in many instances.

columns.Bound(m => m.DateCreatedDate).Template(@<text></text>).Title("Date Created").ClientTemplate("#=kendo.toString(DateCreatedDateTime,'M/d/yyyy hh:mm tt')#").Width(170).Format("{0:M/d/yyyy}");
0
Kiril Nikolov
Telerik team
answered on 05 Feb 2015, 02:03 PM

Hello Bob,

If you want to implement all client operations, you can use template to pass the date with the time porting and filter on a separate field, that is date only. Here is an example:

http://dojo.telerik.com/@Kiril/IDiMU

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bob
Top achievements
Rank 1
answered on 05 Feb 2015, 02:06 PM
Thanks Kiril, but I need an example with the server widget as I don't plan to convert over to the pure client-side version.
0
Kiril Nikolov
Telerik team
answered on 09 Feb 2015, 08:48 AM

Hello Bob,

The implementation is the same with the server widgets, please try to implement it in your project and if you stumble upon any particular issue, please do not hesitate to contact us.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bob
Top achievements
Rank 1
answered on 09 Feb 2015, 01:39 PM
Hi, I understand that you are saying the implementation is the same, but I am paying for the server-side widgets and so I am familiar with that syntax.  Can you please provide this in the syntax for the tool we are paying for?
0
Kiril Nikolov
Telerik team
answered on 10 Feb 2015, 09:36 AM

Hello Bob,

Please note that the standard support services, do not provide on demand coding. As an exception I have prepared an example and you can find it attached here.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bob
Top achievements
Rank 1
answered on 10 Feb 2015, 02:26 PM
Kiril, thanks for the example.  This does not appear to satisfy my requirement for sorting on datetime.  If this is possible or am I missing something, please let me know.

Requirements:
1) Display date and time
2) Sort by date, then time
3) Filter by date only
0
Kiril Nikolov
Telerik team
answered on 12 Feb 2015, 09:32 AM

Hello Bob,

I am afraid that the sorting can only be done by the value that is bound on the column - in your case the value without the time portion. The scenario that you describe in your latest post cannot be achieved with client side operations only.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Kjell
Top achievements
Rank 1
answered on 25 Jan 2017, 08:05 PM
 

Hi, I'm sorry to bring up an old post but I think I've found a solution and want to share and hopefully save others some time.  Or if there is a problem with the way I'm doing it please let me know.

I'm defining two fields, one with the time stripped out ("EventDateFilter") and one with the full datetime ("EventDate").  I'm binding to EventDateFilter and then displaying EventDate in the template. 

So that's a pretty easy solution for Filtering and Grouping, but still leaves sorting.  For that I override the sort manually when it is set to EventDateFilter.  This is in the databound event (since there is no sorting event that I know of).

If there is no sort yet I default it to the EventDate so you may or may not want that behavior.  I'm tracking the last direction in a "private" variable which is probably a little goofy but seems to be working.

I can only think of two issues:

1. The sort happens twice, no big deal in my case.
2. The sort indicator does not appear in the column header, probably a way to do that manually but I dont care at the moment.

 

var grid = $("#gridTimeEntry").data("kendoGrid");
 
//set default sort
if (grid.dataSource.sort().length == 0) {
    grid.dataSource.sort({ field: "EventDate", dir: "asc" });
}
else {
    if (grid.dataSource.sort()[0].field == "EventDateFilter") {
        log.info("overriding filter");
 
        if (_sortDirection == "asc") {
            _sortDirection = "desc";
        }
        else {
            _sortDirection = "asc";
        }
 
        grid.dataSource.sort({ field: "EventDate", dir: _sortDirection });
 
    }
}

 

0
Boyan Dimitrov
Telerik team
answered on 27 Jan 2017, 02:58 PM

Hello Kjell,

Thank you for sharing your solution with the community. 

Actually starting from the Kendo UI 2016 R3 (2016.3.914) release there is a sort event available in  the Kendo UI Grid options. The event is fired when the user is about to modify the current state of sort descriptors of DataSource via the sort UI.

Regards,
Boyan Dimitrov
Telerik by Progress
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
Bob
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Bob
Top achievements
Rank 1
Kjell
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or