associating sorted dates with divs they originated in (before sorting)
<p>I have a collection of parent <code>div</code>s that are labeled with  unique order numbers based on their <code>id</code>, so like, <code>&lt;div id='parent_uniqueID'&gt;</code> . They each have child divs which contain information on the order: order number (same as above), name, and order date (mm / dd / yy). </p>

<p>I am attempting to sort these parent divs based on each of these columns.</p>

<p>Its easy to sort by the order number and rearrange the parent divs. I sort them, then select the parent divs with something like $('#parent_' + order_number);` And I append them to the page. Also simple for alphanumeric; at the end of the alphanumeric string, I append the order, before I sort it. Which is handy because that way if two orders have an identidcal name, the parent divs default to sorting by order number. </p>

<p>I have no idea though how to, once finished sorting by date, distinguish which date belongs to which parent div, so that I can grab the parent divs by the <code>ids</code> and rearrange them on the page.</p>

<p>When I was trying to understand sorting numerically, I received <a href="http://stackoverflow.com/a/11146962/1252748">this really nice solution</a>, which I am trying to adapt to dates:</p>

<pre><code>$('.sortable').click(function () {
    if ($(this).hasClass('sortable_date')) {

        var sort_order = sort_class_distribution($(this)),
            sort_column = this.id.replace("header_", "") + "_div",
            content2 = $('#currentOrdersContent2'),
            date_holder = "",
            i = 0;



        var sorted = $('.' + sort_column).map(function () {

            date_holder = $.trim($(this).text());
            //get order number from parent div
            //only_numbers function strips out everything but numbers
            cur_order = only_numbers($(this).parents('.order_details_bg_trigger').attr('id'));


            //check that the text is not "Not given" or "Unavailable"
            if (date_holder.indexOf("/")) {
                cur_date = date_holder.split(" / ");
                //change the text string into a proper javascript date
                return new Date(cur_date[2], cur_date[0] - 1, cur_date[1]);
            } else {
                //if it is 'Not given', assign it today's date
                return new Date();
            }
        }).toArray().sort(sort_order = "asc" ? date_sort_asc : date_sort_desc);


        //change javascript date back to mm / dd / yy format
        //weak attempt to match sorted dates with dates contained in table
        $.each(sorted, function (i, item) {

            cur_date = ('0' + (item.getMonth() + 1)).slice(-2) + ' / ' + ('0' + item.getDate()).slice(-2) + ' / ' + item.getFullYear();

        });

    }

});
</code></pre>

<p>These are the date sort functions:
<em>source: <a href="https://gist.github.com/1772996" rel="nofollow">https://gist.github.com/1772996</a></em></p>

<pre><code>function date_sort_asc(date1, date2) {
    if (date1 &gt; date2) return 1;
    if (date1 &lt; date2) return -1;
    return 0;
}

function date_sort_desc(date1, date2) {
    if (date1 &gt; date2) return -1;
    if (date1 &lt; date2) return 1;
    return 0;
}
</code></pre>

<p>Any suggestions on how to do this, or a new patten are welcome. Thanks!</p>
