Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
Infragistics Angular Data Grid Date Column giving error on empty string
posted

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

Parents
  • 2700
    Offline posted

    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 Pachilova
    Associate Software Developer

  • 2700
    Offline posted in reply to Arunava Chakraborty

    Hi Arunava,

    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.

    Best regards,
    Bozhidara Pachilova
    Associate Software Developer

Reply Children