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

Date Filter and binding is not working

5 Answers 730 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vijay
Top achievements
Rank 1
Vijay asked on 31 Mar 2020, 06:14 PM

Hello

We have tried to bind the data and add the filters for date columns and its not working as expected.  Our Datasoure returns the following Json Results, after calling the Process Method, its takes the following values and not binding property.  If we take json data data and add it in .ts file, its binding properly and filter is not working. 

{data: "[{"DonorNa", total: 13489}
data: "[{"DonorNa"
total: 13489
__proto__: Object

 

this.gridData = process(this.gData, this.state);

[{"DonorName":"CRESSSTEST, BRIANZTEST","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2017-07-12T14:16:03","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"CRASS, BRIN","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2017-07-14T14:14:12","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BRIANTEST, CRESSTEST","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2017-07-18T08:35:31","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BRTEST, CRETEST","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2017-07-14T11:05:45","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST, LAST","CollectedDate":"2019-09-09T16:10:43","ReceivedDate":"2019-09-09T16:10:42","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST, TEST","CollectedDate":"2019-09-16T11:56:14","ReceivedDate":"2019-09-16T11:56:14","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BROOKS, ANTOINE H","CollectedDate":"2019-08-13T08:00:00","ReceivedDate":"2019-08-14T08:45:51","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST, TEST","CollectedDate":"2019-09-06T09:54:28","ReceivedDate":"2019-09-06T09:54:27","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST, TESTA","CollectedDate":"2019-10-03T10:00:00","ReceivedDate":"2019-12-10T17:24:22","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WARREN, ENRIQUE D","CollectedDate":"2016-07-19T10:46:05","ReceivedDate":"2016-07-20T08:29:05","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"MC LEAN, HERMAN B","CollectedDate":"2016-07-19T15:08:00","ReceivedDate":"2016-07-21T11:09:35","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WILKINSON, WILLIE R","CollectedDate":"2016-07-19T17:22:00","ReceivedDate":"2016-07-20T13:11:35","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"ROBLES, CARRIE T","CollectedDate":"2016-07-19T19:25:00","ReceivedDate":"2016-07-21T09:37:28","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"NICHOLS, NIKKI G","CollectedDate":"2018-01-30T11:54:06","ReceivedDate":"2018-01-31T08:02:11","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"CHURCH, GUILLERMO N","CollectedDate":"2015-10-19T07:06:00","ReceivedDate":"2019-01-02T12:01:57","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BRUCE, MELINDA R","CollectedDate":"2016-07-20T15:09:00","ReceivedDate":"2016-07-21T11:43:20","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"FIGUEROA, JONI D","CollectedDate":"2016-07-20T17:20:00","ReceivedDate":"2016-07-21T14:02:14","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"HANCOCK, LAUREN T","CollectedDate":"2016-07-19T15:35:00","ReceivedDate":"2016-07-20T08:26:54","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"RUIZ, RALPH K","CollectedDate":"2016-07-19T08:50:00","ReceivedDate":"2016-07-20T09:43:33","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"HO, DEANA G","CollectedDate":"2016-07-20T15:22:00","ReceivedDate":"2016-07-21T12:25:33","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WILLIAMS, JOHNNY C","CollectedDate":"2016-07-20T12:55:00","ReceivedDate":"2016-07-21T11:45:02","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"LOVE, AUDREY T","CollectedDate":"2016-07-20T11:49:00","ReceivedDate":"2016-07-21T11:09:49","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BLEVINS, JENNIFER R","CollectedDate":"2016-07-20T14:35:00","ReceivedDate":"2016-07-21T11:35:30","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"DAUGHERTY, RENE C","CollectedDate":"2016-07-20T12:09:00","ReceivedDate":"2016-07-21T11:22:25","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"PERKINS, RUTH O","CollectedDate":"2016-04-22T10:06:00","ReceivedDate":"2019-01-02T11:21:52","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WALLER, LAURIE C","CollectedDate":"2012-10-11T00:00:00","ReceivedDate":"2012-10-11T09:27:44.81","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST, TEST","CollectedDate":"2019-09-06T09:54:28","ReceivedDate":"2019-12-12T09:55:58","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WHITE, GINGER C","CollectedDate":"2018-10-25T08:00:00","ReceivedDate":"2018-12-19T11:20:13","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WHITE, GINGER C","CollectedDate":"2018-10-25T08:00:00","ReceivedDate":"2019-01-02T10:13:05","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"HUNT, KRISTIAN Z","CollectedDate":"2014-11-10T00:00:00","ReceivedDate":"2014-11-13T10:59:41","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BENITEZ, ARLENE B","CollectedDate":"2016-07-19T16:30:00","ReceivedDate":"2016-07-21T12:40:38","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"DOWNS, ROMAN E","CollectedDate":"2017-09-30T08:21:00","ReceivedDate":"2019-03-07T12:55:16","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BOYLE, FRANCISCO T","CollectedDate":"2016-07-20T14:33:00","ReceivedDate":"2016-07-21T13:49:14","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WATERS, DEMOND C","CollectedDate":"2016-07-15T21:08:00","ReceivedDate":"2016-07-19T08:52:38","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"GATES, CAREY S","CollectedDate":"2016-08-08T13:21:00","ReceivedDate":"2016-08-11T14:48:09","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"CRESTTREST, BR","CollectedDate":"2017-05-31T01:00:00","ReceivedDate":"2017-07-14T14:28:49","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST, TEST","CollectedDate":"2019-09-16T12:01:35.657","ReceivedDate":"2019-09-16T12:01:35.627","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"Hhjhggghhj","CollectedDate":"2018-07-18T13:22:00","ReceivedDate":"2017-07-12T10:27:29","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"BRIANTEST, CRESSTEST","CollectedDate":"2017-07-03T00:00:00","ReceivedDate":"2017-07-12T10:13:13.81","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TERTEROSA, TESTER","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-08-02T14:56:51.91","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TESTCRESS, TESTBRIAN","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T11:43:28.62","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":", ","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T12:14:51.21","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":", ","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T14:16:46.907","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST-BRIAN, JO","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T14:32:01.217","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST-BRIAN, JOSEPH","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T14:34:39.563","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TESTCRESS, BRIANTEST","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T15:59:31.583","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"TEST-BRIAN, TESTCRESS","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T13:50:54.693","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":", ","CollectedDate":"2099-12-31T00:00:00","ReceivedDate":"2018-06-07T12:06:57.127","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"WHITE, GINGER C","CollectedDate":"2018-10-25T08:00:00","ReceivedDate":"2018-10-30T12:39:34","ReportedDate":"2099-12-31T12:00:00"},{"DonorName":"MERCADO, PATRICIA W","CollectedDate":"2018-02-26T08:00:00","ReceivedDate":"2018-02-27T12:24:03","ReportedDate":"2099-12-31T12:00:00"}]

5 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 02 Apr 2020, 08:21 AM

Hello Vijay,

The built-in Grid functionalities like formatting, filtering, sorting, grouping, and editing, need the Grid data to contain actual JavaScript Date objects (not some string date representations) in order to be working as expected:

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

When the data contains strings, they will be processed as such, yielding unexpected results. Furthermore, the built-in Grid date filtering UI is the DatePicker component whose value can be a JavaScript date object only, thus comparing the value of the DatePicker to a string value will not yield a valid result.

Mapping the incoming data such that JavaScript Date objects are produced from the string date representations is the most straight-forward approach to ensure that the Grid is dealing with the dates properly.

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.
0
Vijay
Top achievements
Rank 1
answered on 02 Apr 2020, 05:59 PM

After Changing the Value, i am able to bind the data in the GRID, but the filter is not working.

The Received Date changed into this format.

DonorName: "BRIANTEST, CRESSTEST"
CollectedDate: "2099-12-31T00:00:00"
ReceivedDate: Tue Jul 18 2017 08:35:31 GMT-0500 (Central Daylight Time) {}
ReportedDate: "2099-12-31T12:00:00"

0
Dimiter Topalov
Telerik team
answered on 06 Apr 2020, 09:23 AM

Hi Vijay,

I created an example using the provided dataset, mapped so that the items contain JavaScript Date objects, and it seems to be working as expected:

https://stackblitz.com/edit/angular-nqnxvj?file=app/products.ts

Note that the respective Grid column filter input is set to "date" so that the default UI for filtering dates is used. Also, in the dataStateChange event the state is updated, and the data is processed accordingly.

Further details about Grid data binding and filtering are available in the following sections of our documentation:

https://www.telerik.com/kendo-angular-ui/components/grid/data-binding/automatic-operations/#toc-getting-started

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

Please compare it to your implementation, and apply the necessary adjustments. If the issue persists, we will need a similar isolated runnable project where it can be observed, so we can inspect it, determine what is causing it, and try to suggest a solution that is most suitable to the specific use case. Thank you in advance.

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.
0
Vijay
Top achievements
Rank 1
answered on 07 Apr 2020, 02:59 AM

The filter is not working in the stackblitz.  I entered 9/9/2019 and changed the filter option to Is Equal to, its not showing up any value.

Attached the screen shot for your reference.

0
Dimiter Topalov
Telerik team
answered on 08 Apr 2020, 08:06 AM

Hi Vijay,

The filter is working as expected - when two dates are compared, their time part counts too, and the date April 8th, 2020, 2 PM is different than the date April 8th, 2020, 4PM. When a date is selected from the DatePicker, it is created with 0 time part - midnight of the selected date.

Thus to match date-times for the whole day where the hour portion of the date can be from 0 to 23, the used filter should be "later than or equals this day AND is before the next day", for example:

https://www.telerik.com/kendo-angular-ui/components/grid/filtering/#toc-filter-menu

https://stackblitz.com/edit/angular-nqnxvj-w1rf4e?file=app/app.component.ts

Alternatively, the developer can modify the incoming filter object in the dataStateChange event in accordance with their needs, for example if a filter descriptor by the date field comes, and its operator is "eq", replace it with a composite descriptor with logic "and", and filters as described above = 'gte' the incoming date and 'lt' the next date, for example:

{
  filters: [{field: 'dateField', operator: 'gte', value: the-incoming-filter-date-value}, {field: 'dateField', operator: 'lt', value: the-incoming-filter-date-value + 1 day}], logic: 'and'
}
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
Vijay
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Vijay
Top achievements
Rank 1
Share this question
or