Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Order of value map

    I recently converted optionDataSource for "static data" into value maps with the idea of making the code leaner and more easy to read. I used to have a certain order in that data, but now that I use a value map that order seems to have gone. Is this fixable?

    So I had something like this to filter by dates:
    Code:
    optionDataSource: isc.DataSource.create({
      cacheData: [
        { code: '2024', name: '2024' },
        { code: '2023', name: '2023' },
        { code: '2022', name: '2022' }
      ],
      clientOnly: true
    })
    And now I have this:
    Code:
    valueMap: {
      2024: 2024,
      2023: 2023,
      2022: 2022
    }
    But it displays in order 2022, 2023, 2024.

    #2
    Hi wallytax

    I‘m pretty sure I asked the same question before and a client only DataSource is the way to go.

    Best regards
    Blama

    Comment


      #3
      Thanks for your reply Blama!

      That would really be disappointing: I've just migrated all data sources to value maps to find out about this. Is this something JavaScript does? I can imagine that the order of key/values in an object is not guaranteed. Would it be an option for SmartClient to support 2-dimensional arrays as value map? Or support the option to pass an array of objects (similar to the cache data in the first peace of code in my first message) and use valueField and displayField?

      I know I can use the 1-dimensional array which for this particular case, but I also have data were code and name are not the same.

      Comment


        #4
        Unfortunately, this is a change made to the JavaScript language some years ago for "efficiency". We thought it was very stupid and argued strongly against it, but it was done anyway.

        A DataSource is necessary if you have property values in your value map which are parseable as numbers. There is no declaration shorter than creating an Array, but if this is a recurring need, you can create a utility method to eliminate the minor framing necessary to turn that into a DataSource.

        Comment


          #5
          Thanks for that reply! I will use a data source in situations like these, knowing that it is the only option.

          Comment

          Working...
          X