Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mgratch/77ae9030de8feff53dc988962f1a176f to your computer and use it in GitHub Desktop.
Save mgratch/77ae9030de8feff53dc988962f1a176f to your computer and use it in GitHub Desktop.
run from web console. Sort invoice items by date.
var items = [];
//build an array of item id's and date the item was logged
jQuery.each(jQuery(".redactor-editor > p > small:last-child"), function(){
var date = jQuery(this),
item = jQuery(this).parent();
items.push({date: new Date(jQuery(this).text()),ID: jQuery(this).parents('.item').first().data('id')})
})
//yay underscores makes sorting by date easy
var final_items = _.sortBy(items, 'date'));
//rearrange the items from oldest to newest
jQuery.each(final_items, function(){
jQuery('.items_list').append(jQuery('.items_list').find('.item[data-id="'+this.ID+'"]').remove());
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment