Dealing with a specific issue myself, I discovered that JavaScript reads numerical values alphabetically. This means that numbers like 1-9 are fine, but once you reach double digits, such as 10, it can be interpreted incorrectly because only the first number is considered.
To resolve this issue, I decided to prepend additional numbers to my ID so that all IDs were the same length. For example, using numbers like 1000, 1001, 1002 up to 9999 (if surpassing 10,000 entities, an extra zero can be added).
I utilized MySQL to modify the numbers while extracting data. Here's an example of how the code looked:
$sortnum = $row['id'];
$sortnum = "1".str_pad($sortnum, 4, '0', STR_PAD_LEFT);
For instance, if the original ID was 10, after modification it would become 10010, and for 2 it would be 10002. This ensured that JavaScript accurately interpreted the numeric order.
This might not be the most conventional method, but it served its purpose for me until I discover a more efficient solution.
Edit:
If your ID slot is reserved for another usage, an alternative approach could involve sorting based on content. Simply hide the previous ID within the content itself, allowing vis.js to order items by setting groupOrder to 'content' in the options.