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 Reply
  • 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

Children