We have authored a page and the nodes on the crxde getting created based on the sequence of the authoring. Let's say, I have 3 parsys on page par1 , par2 and par3. If I start authoring with par3 - it will be first node that gets created and then if I author par1 and then par2, then the order of nodes appears in page in JCR is jcr:content
We've created a custom JSON response similar to -1.json which produce the JSON structure based on node order and it's being consumed for the mobile website. Now, the problem here is, since the par3 is being authored at start, it appears as first nodes in JSON however, the since the par3 is at the bottom of page in page component so when we see actual page, it appears at the bottom. But, as the mobile site is being generated based on JSON structure, the bottom content of page(desktop website) appears at the top on mobile website. So, is there any way to display the content in mobile site in similar order as it is on desktop website?
I opened localhost:4502/editor.html/content/we-retail/us/en/experience.html
At the bottom I added 3 text components to the responsive grid and added the content "text1", "text2" and "text3" into them.
I checked the order of the nodes below /content/we-retail/us/en/experience/jcr:content/root/responsivegrid and found, that the order in the JCR follows the order in the page: first there is the text component containing the text "text1", then the component for "text2" and finally the component for "text3".
Then I changed the order of the components in the page by dragging the text3 component directly below the text1 component, so on the page the order is now "page1", "page3", "page3".
I validated in the CRXDE that the ordering of the nodes in the JCR has changed as well.
This means, that in a parsys (or a responsive grid) the order of the components in the JCR and the order in the page are always identical. No matter in what order you created them. Just the order matters. And when you iterate through the child nodes of that "responsivegrid" node using your own code, you will get exactly this order!
Outside of the parsys or responsive grid the situation is different. Here the order typically does not matter, also because an author cannot just drag components into the page, but you as developer / template editor have to add them explicitly. And of course then order is not defined. But your (page) components should know how to deal with that situation, and you should add that logic to your custom JSON exporter too.
(And by the way: If you use the Sling Model Exporter, you can eliminate quite a bit of code ...)