Mapping date object when value is null, datatable date sorting

edited December 2018 in Technical questions

I've got some datatable columns with dates that I want to sort. I understand I have to map these string values to date objects. However, not every row has a date. In case of no date, the json returns a null. In this case, the outputted date will be shown as "NaN/NaN/NaN", the sorting also seems to behave strangely. Any way to just ignore null values and have them rendered as blank?



  • Any advice on this issue? Am I implementing it wrong? It's a fairly big issue as it affects editing of cell data (date type error in SQL). Surely I can't be the first to sort a date column with empty values.

    One idea I did have is to not use render_sql and manually return empty strings for null values.

  • edited December 2018


    You can try defining a data scheme instead of mapping.
    It will allow for better control over the data:

  • edited December 2018

    Thank you! It seems to solve the problem, however I have run into a new issue when binding with this date value.

    As you can see, in the htmlform the date format is probably not ideal. I understand the problem is the htmlform does not have a format property like datatable so the date is displayed as the full original date object. Possible to define the dateformat in the scheme?

    If I change parseFormatDate to dateFormatStr it looks great, but no longer sorts.

  • Is there any possible solution to this?

  • You can use events instead of direct binding and control the date that is set into the form and pushed back to the datatable:

  • edited January 9

    Thanks for the solution. However, direct binding is important because the user can make changes via both the datatable and form. Bind ensures both views are always in sync and updated which is very important. Is there a reason for the formatting of the date in the binded view? I simply want to sort a date displayed in a common format and bind exactly how it appears to the htmlform. Should it really take so much modification for such functionality?

    Also, from your example I modified it so that it displays the US date format in the form view. Not sure if I did this right. When I save the form, the date isn't sent correctly to the datatable.

    If this is the only approach, then there is 1 other issue. I noticed the form doesn't update immediately when value is changed in datatable. I tried to invoke a refresh, but it doesn't seem to work.

    Thank You

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion