Trying to find a way to order a dynamically generated list of names that have itereactive sub menus in alphabetical order of surname. The script first populates a list of active users and then updates it based on user activity removing inactive users and appending active users.
Instead of appending these at the bottom of the container I want to insert them into the list in alphabetical order of surname integrating it with those already there.
Taking those already there and putting them into an array would interrupt any user activity on the interactive sub menus each of these has.
I'm thinking that when the content is generated we could assign it a number in on the div (data-sortorder for example). That number would be generated based on the surname of each user. How then would we be able to insert new content based on the nearest sortorder value that is smaller than the current sortorder, or is there a better way of doing this.
// Content that is inserted
<div data-id="" data-sortorder="">
<div class="text"> Jerry Smith </div>
<div class="submenu"> ... </div>
</div>
// Example
Lets say this already exists in the container
<div class="container">
<div class="user" data-sortable="5210">
<div class="text"> Jerry Smith </div>
<div class="submenu"> ... </div>
</div>
<div class="user" data-sortable="5720">
<div class="text"> Jerry Smith </div>
<div class="submenu"> ... </div>
</div>
<div class="user" data-sortable="5914">
<div class="text"> Jerry Smith </div>
<div class="submenu"> ... </div>
</div>
</div>
Then we get some new data via ajax thats in an object (e). We know that we have say three new users with a sortable value of 5341 and 6710. So we want to insert the html (also in e) of 5341 after the second .user div we already have and the second on of 6710 after the last div we currently already have.