Issue #4 resolved

Option to hide empty optgroups

Anonymous created an issue

Add option setting to hide headers for empty optgroups

Comments (7)

  1. lhaemmerle

    Find below a patch for updateListFilter(textControl) that hides empty categories/optgroups:

    [...]
    //show nomatches item, and no other headers if the filter excludes everything
    var anyMatches = Boolean(listItems.filter(':visible').length!=0);        
    listControl.children('.idd_listItemGroupHeader').toggle(anyMatches);
    listControl.children('.grpHdrNoMatches').toggle(!anyMatches);
    
    // Hide visible but empty categories
    var previousElement = null;
    var allListItems = listControl.children().filter(':visible');
    allListItems.each(
    	function () {
    		if ($(this).hasClass("idd_listItemGroupHeader")){
    			if (previousElement != null && previousElement.hasClass("idd_listItemGroupHeader")){
    				//alert("Hide " + previousElement.text())
    				previousElement.hide();
    			}
    		}
    		previousElement = $(this);
    });
    
    // Hide last visible item if it is a category
    if (allListItems.last().hasClass("idd_listItemGroupHeader")){
    	allListItems.last().hide();
    }
    
    positionList(listControl); //resize list to fit new visible elements.
    
    [...]
    

    What is missing is a switch to make this an option.

  2. lhaemmerle

    That last condition actually should be:

    if (allListItems.last().hasClass("idd_listItemGroupHeader") && !allListItems.last().hasClass("grpHdrNoMatches")){
    

    which ensures that the "No match found" entry is not hidden as well.

  3. Log in to comment