I’m trying to load some data into a list of options for a select box.
The data url I’m using loads in 4 elements for my table (name, temp, sent, available). In the grid I just attach those to the right columns and everything loads fine. I’d like to load just a list of the names into a select box.
Which loads in the proper number of names, but each selection is “undefined.” I’m assuming that’s because it’s loading in an object that contains name/temp/sent/available instead of just the one property I want (“name”).
ui.select is an html-based control and not so customizable. By default, it expects the id-value pair. As for your dataset, I can suggest using ui.richselect and
Ah, that makes sense. Richselect works, but I think I’m favoring syncing a combo box with a datacollection, though (as roughly shown through this sample: http://docs.webix.com/samples/80_docs/getpopup.html).
curOptions is the full data collection of names (like {“Joe”,“James”,“Frank”}) etc., and it loads that data as options for the combo box fine.
curName is the current name from the selected cell on my grid. When I try to do this the default set value of the combo box still stays blank, despite the string I’ve gotten being a valid option in the list. Do I need to somehow get the ID of the option value or something?
Hmm, okay. Is there a way to “search” through the list for a certain input, get the id of that value, and then set the control’s value to that id? I have two different data sources (one with names currently on the datatable and one with all possible selectable names) and am trying to link it so when the user selects a row on the grid, it selects that takes the “name” from the selected row and picks that as the default value for the combo box. I don’t think I can attach the ids from the data because they’re different.
I’m trying to do it with find, but it’s not coming up with anything (hard coded value in for testing purposes):
Edit: My not so elegant solution otherwise is to do a for loop through all of the items in the list and compare the selected name from the grid to the name in my name options list and stop when it finds the right value, grab the id of that corresponding value, then set the combo box’s value to that id.
The find in above code must work correctly.
The only case, when problem can occur, if you are using the above code just after ui creation, and data can be not loaded from server yet
Ah, ok. I had a bit of trouble syncing the ids of the objects up in my datacollection and datatable (I could get the corresponding id from the selected datatable row, but had trouble defining the id correctly in my datacollection), which is why I opted to go the linear search route.
Edit 1: I get what you’re saying now and think I’m able to set the corresponding id, I’m trying it now, I’ll edit this again in a little bit when I’ve made a first pass at it. I didn’t realize the id of a combo box would automatically set to a corresponding id from a datacollection.
Edit 2: Ok, I was successfully able to link up the nameids from my datacollection to the combo box’s ids, then just use combobox.setValue to change the combo box to the nameid from the dataset I was using for the datatable. Much more efficient than a linear search