Ordering items

Hi

while adding nodes to the diagram, I add them in a certain order but they are displayed in a different order.
Is there a way to fix this?

I assume that you have set Diagram.layout to a layout. If you have chosen a layout that has a comparer property, you need to set that, perhaps along with setting the sorting property.

I’m using a grid layout,
is there a way to just make it show the elements in the order I added them (they are added to the modek in the correct order),
or do I have to sort them?

That’s actually the default value for GridLayout | GoJS API.

Maybe the property has already been set to another value?

ok, the comparer is working for the first data loaded to the model, but not for the data loaded later on,
do I need to run the comparer again for the loaded data?

and as for what you mentioned, I don’t do any sorting but I don’t load the data sorted alphabetically

also, I can;t set attribute sorting on the layout - I get “Trying to set undefined property sorting on object: DIagram”

If the value of GridLayout.sorting specifies sorting, Ascending or Descending, the GridLayout.comparer is used to sort each time the layout is run.

If the value of GridLayout.sorting is Forward or Reverse, the GridLayout.comparer is not used at all – the order in which nodes are supplied is used (perhaps reversed).

OK, got the sorting property to not give an error,
but still it only works on data loaded before the diagram was rendred, any nodes added to the diagram after rendered are not sorted in any way

BTW, this happens to any other property I give to the diagram like spacing and arrangement, which I also loose for data loaded after draw.?

It’s really hard to guess when we cannot see the relevant code.

How do you initialize the GridLayout that you use for the Diagram.layout (or Group.layout)?

thanks, that question lighted a bulb here:
the problem was in the group template, copied the layout definitions in it and now it works.

thanks again