Ever since I have started using TVs I have been wondering how the TVs were "ordered" when you edit a document. It seemed to me it was set in the order you created them. If you have enough TVs, you’ll notice that’s not exatcly the case. When you have lots of TVs, editing a document can become a bit confusing, things are scrambled...
I have dived into
manager/actions/dynamic/mutate_content.dynamic.action.php and looked at the code to see how things were really going on.
I think I found the code between Line 956 to 1021, at
line 977
$sql.= "WHERE tvtpl.templateid = ".$template." AND (1='".$_SESSION['mgrRole']."' OR ISNULL(tva.documentgroup)".((!$docgrp)? "":" OR tva.documentgroup IN ($docgrp)").") ORDER BY tv.rank;";
Correct me if I am wrong, but it would seem TVs are ordered by rank... now I never noticed the
rank field, but it’s there alright in the
modx_site_tmplvars table.
Now the funny thing is, it has a default value of 0 and, more surprising, it’s not auto-incremented... how can it help sort TVs then ?
Well it does not.
Check your TVs and you’ll see that they all have a "0" value...
Am I wrong in my assumption (remember I don’t read php code fluently

-> I could be dead wrong here) ?
If not, would editing my TVs and assign rank according to the order I want to set work ? (I’d rather ask before breaking anything...)
Also, wouldn’t it be more logical to set the rank field to auto-increment at install ? It seems like this field was planned to be used but never really used : any particular reason ?
Thanks !