Datatype convertion without changing the original itemsource

Posted by: andreas.knuth on 23 May 2019, 1:20 pm EST

  • Posted 23 May 2019, 1:20 pm EST

    Hi,

    I have e.g. the following data structure [itemsource]:

    [{‘number’:‘2,99’,‘bool’:‘true’,‘date’:‘13.10.2019’},{‘number’:‘1,28’,‘bool’:‘false’,‘date’:‘01.12.2018’}].

    These data should be displayed in the following columns:

    • number of type Number (2)
    • bool of type Boolean (3)
    • date of type Date (4)

      This actually does not work because the data’s are strings. Is there a way (e.g. by using the collectionview) to convert the above data without manipulation of the original itemSource ?

      best regards,

      Andreas
  • Posted 24 May 2019, 8:19 am EST

    Hi Andreas,

    We are sorry but there is no direct way to achieve this. You need to format the JSON to correct type before using it with the collectionView.

    You may refer to the following sample which demonstrates the same:

    https://stackblitz.com/edit/js-pqenz4

    Regards

  • Posted 24 May 2019, 12:08 pm EST

    Hi Sharad,

    thanks for your reply. I had almost thought of something like that … but I hoped that there are any getter/setter on cell base.

    regards,

    Andreas

  • Posted 29 May 2019, 4:03 am EST

    You could also use the dataType property of Column to coerce the values into proper data type in the grid. Please refer to the sample below:

    https://jsfiddle.net/t8vn4rjp/

    API Reference:

    dataType:

    https://www.grapecity.com/wijmo/api/classes/wijmo_grid.column.html#datatype

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels