Created
February 8, 2018 18:29
-
-
Save mgratch/77ae9030de8feff53dc988962f1a176f to your computer and use it in GitHub Desktop.
run from web console. Sort invoice items by date.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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