Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter landwire

    (@landwire)

    Ok, I did it. Was not sure if I would manage ??
    Could you incorporate that into your plugin? That would be great. Thanks,
    Sascha

    Here is the code:

    1. Add another button to your form:

    <input type="submit" name="order-alpha" id="order-alpha" class="button-primary" value="<?php _e('Sort Alphabetical', 'customtaxorder') ?>" />

    2. Add some jQuery stuff into your script:

    <script type="text/javascript">
    // <![CDATA[
    	jQuery(document).ready(function(jQuery) {
    		jQuery("#custom-loading").hide();
    		jQuery("#order-submit").click(function() {
    			orderSubmit();
    		});
    		jQuery("#order-alpha").click(function(e) {
    			e.preventDefault();
    			jQuery("#custom-loading").show();
    			orderAlpha();
    			//jQuery("#order-submit").trigger("click");
    			setTimeout(function(){
    				jQuery("#custom-loading").hide();
    			},500);
    			jQuery("#order-alpha").blur();
    		});
    	});
    	function customtaxorderAddLoadEvent(){
    		jQuery("#custom-order-list").sortable({
    			placeholder: "sortable-placeholder",
    			revert: false,
    			tolerance: "pointer"
    		});
    	};
    	addLoadEvent(customtaxorderAddLoadEvent);
    	function orderSubmit() {
    		var newOrder = jQuery("#custom-order-list").sortable("toArray");
    		jQuery("#custom-loading").show();
    		jQuery("#hidden-custom-order").val(newOrder);
    		return true;
    	}
    	function orderAlpha() {
    		jQuery("#custom-order-list li").sort(asc_sort).appendTo('#custom-order-list');
    		var newOrder = jQuery("#custom-order-list").sortable("toArray");
    		jQuery("#custom-loading").show();
    		jQuery("#hidden-custom-order").val(newOrder);
    		return true;
    	}
    	// accending sort
    	function asc_sort(a, b){
            //return (jQuery(b).text()) < (jQuery(a).text()) ? 1 : -1;
    		//console.log (jQuery(a).text());
    		return jQuery(a).text().toUpperCase().localeCompare(jQuery(b).text().toUpperCase());
        }
    
    // ]]>
    </script>
    Plugin Author Marcel Pol

    (@mpol)

    I will look at it, I expectt his weekend.
    It’s a good idea.

    Plugin Author Marcel Pol

    (@mpol)

    Thank you, it’s now part of 2.4.0

    This is awesome and exactly what I needed but… Here’s the gift horse part.

    1) After I set alphabetical order, the admin display goes back to index order. It should maintain whatever order the list is set to display in. It is confusing to have it set for alphabetical order but not see it displayed that way.

    2) Also, if the list is set for alphabetical order, the button should change from “Sort Alphabetical” to “Sort by Index” to return to the index sort.

    What happens if another term is added? Do you have to resort the list?

    Thanks again to BOTH of you for the work you have put in. This is a very helpful plugin!!

    Accidental double post. Couldn’t see how to delete this one.

    Thanks again to BOTH of you for the work you have put in. This is a very helpful plugin!!

    Plugin Author Marcel Pol

    (@mpol)

    Hmm, interesting questions. Maybe there should be something in php then as well.

    I was thinking about the checkbox for auto-sorting, to have there 3 options as radiobutton. Button one (default) for no auto-sorting. Button 2 for custom order. Button 3 for Alphabetically. But that button 3 needs some work then. The filters need to be updated as well.
    I will look at it, but don’t expect it tomorrow.

    Plugin Author Marcel Pol

    (@mpol)

    There is now a different set of options for sorting. Please check out 2.4.2.
    The filters should mostly sort by name by default. If there are problems, please get back on it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Enhancement: Sort Alphabetically Button’ is closed to new replies.