Announcement

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

    Keeping a SelectItem in the same sort order as the value map passed in?

    Hello,

    Is there a way for a SelectItem to maintain the ordering from the value map I set on it? I found that even if the value map is a LinkedHashMap, if the keys contain numbers then SmartGWT internally re-sorts it for the SelectItem based on the numeric keys instead of preserving the ordering of the LinkedHashMap. I am just calling selectItem.setValueMap(myLinkedHashMap) and I don't understand why it is re-sorting it based on the numeric keys of the map.

    I don't want to use setSortField() because it looks a little ugly - I don't want the user to need to see that it has the display field's sort enabled in the header. I would just like the values to stay sorted the same way they are in the LinkedHashMap.

    Also is this something you could fix on your end? If you pass a LinkedHashMap into selectItem.setValueMap(), shouldn't it preserve the ordering?
    Last edited by user316; 20 Aug 2020, 08:37.

    #2
    Unfortunately, this is due to a change in JavaScript behavior, where native JavaScript Objects preserve order except for numeric keys (extremely dumb behavior that we argued against, but they kept it). It doesn't make sense for the framework to use a heavier object structure for normal valueMaps, so we're stuck with this gotcha. You get around it by specifying an optionDataSource with a clientOnly DataSource, in which case record order is of course preserved.

    Comment

    Working...
    X