Infragistics angular datagrid allows for string input in date type columns. But it gives an error for empty string. the entire table errors out. this should not be the case. it should print empty and handle the error. rest of grid should function properly.the expected behaviour happens for undefined.This seems like a bug
Hi Arunava,
Thank you for reaching out!
I have been looking into your question and tested entering an empty value in the “Order Date” column of type ‘date’ in this demo from our documentation. On my side, an empty date value is accepted by the IgxGrid and no errors are observed.
Could you please test the demo on your side as well an tell me if the reported behavior is reproduced? In case it is, please provide the steps you performed.
In case it is not, this will indicate that the issue is most probably local to your own project. What I can suggest, then, would be to fork and modify the documentation demo, trying to reproduce the issue there and sending it back to me, so I can investigate it.
Alternatively, if the behavior cannot be replicated, please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application and attach it in this case. Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.
Thank you for your cooperation.
Looking forward to hearing from you.
Best regards,Bozhidara PachilovaAssociate Software Developer
Hi,
I am not sure about the version number but I can see it. This is the fork of my repo.
https://stackblitz.com/edit/angular-el6btg-74xxxm?file=src%2Fapp%2Fgrid%2Fgrid-column-data-types-sample%2Fgrid-column-data-types-sample.component.ts
I changed OrderDate to '' i get an error
empty string is not handled in this part of the code.
Thank you for clarifying how the empty string value is set!
Please, note that the code that you are referring to is part of Angular’s Common module. You can view the file in GitHub here. This function is itself called by the Angular DatePipe, respectively the formatDate method (source code here).
These methods are used by the grid for columns of type ‘date’. The formatting in the grid only adds coalescing to an empty string in case the value is ‘null’ or ‘undefined’ to the default functionality, so that explains the observed behavior, mentioned in my previous message. When deleting the value of a ‘date’ cell, it remains empty. However, the underlying value is ‘undefined’, which is handled by the DatePipe internally.
For the case of an empty string, though, by going through the toDate method code, you could confirm as to why it is not accepted as a valid date: firstly, it is not an ISO string representing date and secondly, Javascript’s Date function does not parse it. When attempting to declare new Date(‘’) the result is “Invalid Date”. Also Date.parse('') results in 'NaN'.
In conclusion, this would not be considered a bug in this case. Having the column’s type set to ‘date’ and then binding a string value is expected to cause errors.
Nevertheless, in case your original data source does come with empty strings as date values, what I can suggest is the following 'workaround'. It consists of simply setting the date fields values to ‘null’, in case they are initially equal to ‘’:
public ngOnInit(): void { this.data.forEach((d) => { if (d.OrderDate === '') { d.OrderDate = null; } }); }
Here is a modified version of the demo, where the first two data entries are defined as ‘’, and this approach is adopted.
Please, let me know if you need any further assistance on the matter.
HI,I agree that you are just using common's toDate. But should the data sanity not be checked by the grid because as the client I can just pass the data (even if invalid) and expect to atleast see my correct data. Atleast some error handling can be done i guess so that the grid does not crash completely. Kindly give share your thoughts.On a different note. I found that infragistics grid can take '' (empty string) in a 'number' type column. Is that not also unintuitive or incorrect? Should the numberParser (of angular/common) not throw an error in this case? Or is it handled by the grid?Thanks
I agree that this is not a consistent behavior in this case. Thank you for pointing that out!
After further investigation, I determined that the Angular DatePipe handles the empty string case in its transform method before passing the value to the formatDate method. For the grid cell component, there is a place, where the Angular’s formatDate method is called, however, the empty string handling is indeed missing, which leads to the observed behavior.
After reaching out to the development team, they confirmed that this should be fixed on our end. As a result, this issue is logged in our GitHub repo here.
In order to receive a notification whenever new information is available, please make sure that you are subscribed to the issue. Until it is fixed, you could adopt the previously suggested workaround.
Please let me know if you need any further assistance regarding this matter.
Best regards,Bozhidara Pachilova
Hi,Thank you for taking the time out to dig deeper into the problem. I have two questions -
1> I see the issue has been fixed. Does that mean a patch release has also been made?
2> Were you using your custom date pipe but angular's formateDate() method? If so why did you take this approach an not directly use angular's date pipe? (I am asking because i want to know any design decisions you made which might increase my knowledge).Thank you for taking the time out to answer my questions. Learned a lot from this thread.Regards,Arunava Chakraborty
We are glad that you find our suggestions helpful!
The fix has made it into the latest patches for the corresponding versions it targets -13.2.11, 14.0.12. For a complete list of our Releases history, please check out this page in GitHub.
Regarding your second question, Angular’s DatePipe was directly used in previous versions. It is still used for the date cell value in the cell component’s template. The error you observed stemmed from the cell’s title property getter, which also needs to format the value. What I can say is that I am not really familiar with the design decision behind this, as I was not involved in it, however, it seems that the difference might be the related to the handling of undefined and null values in this case.
I hope your issue is now resolved. Thank you for your cooperation.