[richfaces-issues] [JBoss JIRA] (RF-4308) rich:pickList: keep sort order of source list after add/remove operations

Val Blant (JIRA) jira-events at lists.jboss.org
Tue Dec 3 18:46:08 EST 2013


    [ https://issues.jboss.org/browse/RF-4308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924210#comment-12924210 ] 

Val Blant edited comment on RF-4308 at 12/3/13 6:44 PM:
--------------------------------------------------------

I have an easy fix for this problem that seems to work pretty well. Just include this _orderedPickListFix.js_ in your app, and the pickLists should start behaving.

{code:javascript|title=orderedPickListFix.js|borderStyle=solid}
/**
 * This is an extension to the RichFaces PickList that preserves the original order of items in the source list
 * 
 * @author Val Blant
 */
if ( typeof window.RichFaces.ui.List != 'undefined' && !window.PickListExtension ) {
	
	window.PickListExtension = {};
	
	
	if ( typeof window.RichFaces.ui.PickList != 'undefined' ) {

		/**
		 * Overriding original constructor found in "org.richfaces/pickList.js" resource
		 */
		window.RichFaces.ui.PickList = function(oldPickListConstructor) {
			return function(id, options) {
				// Instantiate the original PickList
				//
				var pickList = new oldPickListConstructor(id, options);
				
				// Assign item indecies to each item in the source list to preserve original order
				//
				pickList.sourceList.items.each(function( index ) {
					this.itemIndex = index;
				});
				
				return pickList;
			};
		}(window.RichFaces.ui.PickList);
		
	}
	
	
	
	/**
	 * Original code taken from "org.richfaces/list.js" resource
	 */
	(function($, rf, list) {

	   /**
	    * Insert items into a pick list according to their original order stored in 'itemIndex' attribute
	    */
	    list.prototype.addItems = function(items) {
               var parentContainer = this.scrollContainer;
               
               items.each(function() { 
                   if ( parentContainer.children().length <= this.itemIndex ) {
                   	parentContainer.append(this);
                   }
                   else {
                	itemAtOurIndex = parentContainer.children()[this.itemIndex];
                	jQuery(this).insertBefore( itemAtOurIndex );
                   }
               });
            
               this.__updateItemsList();
               rf.Event.fire(this, "additems", items);			
  	   };
	
     }(jQuery, window.RichFaces, window.RichFaces.ui.List));
}
{code} 
                
      was (Author: vace117):
    I have an easy fix for this problem that seems to work pretty well. Just include this _orderedPickListFix.js_ in your app, and the pickLists should start behaving.

{code:javascript|title=orderedPickListFix.js|borderStyle=solid}
/**
 * This is an extension to the RichFaces PickList that preserves the original order of items in the source list
 * 
 * @author Val Blant
 */
if ( typeof window.RichFaces.ui.List != 'undefined' && !window.PickListExtension ) {
	
	window.PickListExtension = {};
	
	
	if ( typeof window.RichFaces.ui.PickList != 'undefined' ) {

		/**
		 * Overriding original constructor found in "org.richfaces/pickList.js" resource
		 */
		window.RichFaces.ui.PickList = function(oldPickListConstructor) {
			return function(id, options) {
				// Instantiate the original PickList
				//
				var pickList = new oldPickListConstructor(id, options);
				
				// Assign item indecies to each item in the source list to preserve original order
				//
				pickList.sourceList.items.each(function( index ) {
					this.itemIndex = index;
				});
				
				return pickList;
			};
		}(window.RichFaces.ui.PickList);
		
	}
	
	
	
	/**
	 * Original code taken from "org.richfaces/list.js" resource
	 */
	(function($, rf, list) {

	   /**
	    * Insert items into a pick list according to their original order stored in 'itemIndex' attribute
	    */
	    list.prototype.addItems = function(items) {
               var parentContainer = this.scrollContainer;
               
               items.each(function() { 
                   if ( parentContainer.children().length < this.itemIndex ) {
                   	parentContainer.append(this);
                   }
                   else {
                	itemAtOurIndex = parentContainer.children()[this.itemIndex];
                	jQuery(this).insertBefore( itemAtOurIndex );
                   }
               });
            
               this.__updateItemsList();
               rf.Event.fire(this, "additems", items);			
  	   };
	
     }(jQuery, window.RichFaces, window.RichFaces.ui.List));
}
{code} 
                  
> rich:pickList: keep sort order of source list after add/remove operations
> -------------------------------------------------------------------------
>
>                 Key: RF-4308
>                 URL: https://issues.jboss.org/browse/RF-4308
>             Project: RichFaces
>          Issue Type: Feature Request
>      Security Level: Public(Everyone can see) 
>          Components: component-selects
>    Affects Versions: 3.2.2, 4.3.4, 5.0.0.Alpha1
>            Reporter: Martin Höller
>              Labels: low_hanging_fruit, order, picklist, sort
>             Fix For: 5-Tracking
>
>
> When adding items from the source list to the target list and removing this items again, the original order of the source list is not preserved. This makes it hard to find items in a list that is longer than just a fest items. A good example is the second example on the livedemo at http://livedemo.exadel.com/richfaces-demo/richfaces/pickList.jsf. Add the first state (Alabama) and remove it. It can now be found at the very end of the otherwise alphabetical list of states. This can be rather unintuitive for a user.
> My suggestion is either remember the original sort order of the source list, or add some attribute that enables automatic sorting.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira



More information about the richfaces-issues mailing list