Column Auto Reordering

Answered
Christopher Phillips asked on May 6, 2019

Hello I believe we have found 2 issues,

  1. The following Fiddle demonstrates the auto ordering being applied https://jsfiddle.net/y3wdxn58/
  2. Related to that auto ordering we found another issue where the columns are being reordered but the mapping is not being respected. Basically the headers reorder but the dataset itself does not reorder: https://jsfiddle.net/y3wdxn58/1/

The use case we have for numbers as headers is that our users want to use "2018" as the column name. Flexmonster does not seem to auto reorder the columns any other time. We are curious if that is intended or not.
The second example for us is key because we don't want to update every single row with the proper mapping. If you add a space to the end of each number in the second example if resolves the issue but is not ideal.
Thanks,
Chris

5 answers

Public
Vera Didenko Vera Didenko Flexmonster May 8, 2019

Hello, Christopher, 
 
Thank you for pointing this out to us and for providing JSFiddles for illustration.
 
The reason why it works this way lies in the way the browser parses JavaScript and is not an issue of Flexmonster.

There are a few ways the desired output can be achieved:
 
1) By modifying the headers so that they are parsed as strings
 
For example, "2018 year" instead of "2018" 
This way they will not be converted to a numeric type.
 
2) By adding caption and uniqueName parameters
 
Here is a JSFiddle example for illustration.
 
Please let us know if this works and if you have further questions.

Best Regards,
Vera

Public
Christopher Phillips May 8, 2019

Thank for the information Vera but I would like to point out that your JSFiddle doesn't really address the issue. I made one modification and change 0 to a String "Header0" and I still have the issue.

 {
"Header0": {
"type": "string",
caption: "category",
uniqueName: "category"
},
1: {
"type": "string",
caption: "5",
uniqueName: "5"
},
2: {
"type": "number",
caption: "Price",
uniqueName: "Price"
},
3: {
"type": "number",
caption: "1",
uniqueName: "1"
}
},

In lieu of that we've gone ahead and changed our implementation slightly to number the columns as shown in your original fiddle and then added the 'caption' and 'uniqueName' parameters. So the order will be guaranteed regardless of the column name.

Public
Christopher Phillips May 8, 2019

Also Vera we found another issue with that work around please take a look at this jsFiddle https://jsfiddle.net/ha39zeum/1/ 
 
Notice when changing the type it breaks and does not display the numbers properly. The issue is resolved if you remove "uniqueName" parameter.

Public
Vera Didenko Vera Didenko Flexmonster May 9, 2019

Hello, Christopher,
 
Thank you for your reply.
 
We are glad everything worked.
 
When the browser parses the keys, it places numeric ones in order first, then others. So, in your case, the keys will be ordered like this: 1, 2, 3, "Header0".
An important remark is that non-numeric keys can't be used to get values from an array. Such non-numeric keys lead to the undefined result.
 
We would like to note that in the JSFiddle the keys were specified as 0,1,2,... so that the order will be guaranteed regardless of the column name.
 
Regarding the problem when changing the type, our team looked at it in more detail and we see it is an issue.
Our team is currently working on a solution to this issue and the fix will be available in the minor release with the ETA 3rd of June.

Please let us know if you have further questions.
 
Best Regards,
Vera

Public
Vera Didenko Vera Didenko Flexmonster June 4, 2019

Hello, Christopher,
 
We are glad to announce that now it is possible to define uniqueName property in JSON meta object for an array of arrays.
 
This is available in the 2.7.7 version of Flexmonster
 
You are welcome to update the component
 
Please let us know if everything works fine.
 
We are looking forward to hearing from you.
 
Best Regards,
Vera

Please login or Register to Submit Answer