protected override AdvancedDropdownItem FetchData() { AdvancedDropdownItem rootGroup = new AdvancedDropdownItem(label); searchableElements = new List <AdvancedDropdownItem> (); for (int i = 0; i < displayedOptions.Length; i++) { string menuPath = displayedOptions[i]; string[] paths = menuPath.Split('/'); AdvancedDropdownItem parent = rootGroup; for (int j = 0; j < paths.Length; j++) { string path = paths[j]; if (j == paths.Length - 1) { MultiLevelItem element = new MultiLevelItem(path, menuPath); element.ElementIndex = i; parent.AddChild(element); searchableElements.Add(element); if (i == selectedIndex) { SelectedIDs.Add(element.Id); // var tempParent = parent; // AdvancedDropdownItem searchedItem = element; //TODO fix selecting // while (tempParent != null) // { // state.SetSelectedIndex(tempParent, tempParent.children.IndexOf(searchedItem)); // searchedItem = tempParent; // tempParent = tempParent.parent; // } } continue; } string groupPathId = paths[0]; for (int k = 1; k <= j; k++) { groupPathId += "/" + paths[k]; } AdvancedDropdownItem group = parent.Children.SingleOrDefault(c => ((MultiLevelItem)c).stringId == groupPathId); if (group == null) { group = new MultiLevelItem(path, groupPathId); parent.AddChild(group); } parent = group; } } return(rootGroup); }
protected virtual AdvancedDropdownItem Search(string searchString) { if (searchableElements == null) { BuildSearchableElements(); } if (string.IsNullOrEmpty(searchString)) { return(null); } // Support multiple search words separated by spaces. string[] searchWords = searchString.ToLower().Split(' '); // We keep two lists. Matches that matches the start of an item always get first priority. List <AdvancedDropdownItem> matchesStart = new List <AdvancedDropdownItem> (); List <AdvancedDropdownItem> matchesWithin = new List <AdvancedDropdownItem> (); foreach (AdvancedDropdownItem e in searchableElements) { string name = e.SearchableName.ToLower().Replace(" ", ""); AddMatchItem(e, name, searchWords, matchesStart, matchesWithin); } AdvancedDropdownItem searchTree = new AdvancedDropdownItem(SearchHeader); matchesStart.Sort(); foreach (AdvancedDropdownItem element in matchesStart) { searchTree.AddChild(element); } matchesWithin.Sort(); foreach (AdvancedDropdownItem element in matchesWithin) { searchTree.AddChild(element); } return(searchTree); }