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

Grouping Date Time Column but ignore Time Part

1 Answer 400 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vulisetty
Top achievements
Rank 1
Vulisetty asked on 25 Jun 2020, 06:42 PM

Can I group the grid with Date, but ignore the time part?

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 29 Jun 2020, 10:01 AM

Hello Vulisetty,

The built-in Grid data processing functionality (filtering, grouping, sorting) relies on comparing the actual values of the respective column field property in all data items.

The most straight-forward approach to achieve grouping by date (without the time) assuming different data items contain Date values with same day, but different times, is to map the Grid data so that a new custom Date field, containing the trimmed date is introduced. Then the Grid column field can be bound to this new property, while the date with time could be displayed via Cell templates by providing the value of the original date + time field in the template. If displaying the actual times is not necessary, the approach could be simplified by just mapping the data transforming the value of the date property so that the time is always midnight (or other arbitrary value same for all data items).

Here is an example demonstrating the suggested approach:

https://stackblitz.com/edit/angular-kaetxj?file=app%2Fapp.component.ts // both items with date Sept 20 now end up in the same group

It is maybe also worth mentioning that the Grid data needs to contain actual JavaScript Date objects (as opposed to some string representations) for the sorting, filtering, grouping, and formatting to be working as expected:

https://www.telerik.com/kendo-angular-ui/components/grid/troubleshooting/

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Vulisetty
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Share this question
or