I have the requirement to enter the data into comboBox after getting the text from TextBox by pressing the add button. How can i get it done in SmartGWT?
I believe you'll want to start by associating a DataSource with your ComboBoxItem. After that, be sure to call both setValueField(...) and setDisplayField(...) on the combo box. You should start seeing fetch requests get sent when the combo box is instantiated, and the results of the fetch should display in the combo box.
If its not a ComboBox bounded to a datasource its done like this:
Map<String, String> valueMap= new LinkedHashMap<String, String>();
valueMap.put("key","description");
comboBoxItem.setValueMap(valueMap);
Related
Is there a way to pre-populate a MultiSelectList with selected items?
Example:
I have a single View that has the following ListBoxFor that will cause the page to update what it's displaying by allowing filtering of Model.Companies.
#Html.ListBoxFor(m => m.SelectedCompanies, new MultiSelectList(Model.Companies, "IdString", "CompanyName")
What I'd like to have happen is after the update, the MultiSelectList will have the items that were selected before the page updated and refreshed. Does that mean I need to return SelectedCompanies with what was selected, or is there another way?
I am using the javascript library Chosen for usability of the ListBox on the client side, but I don't think that this affects what I'm trying to do.
Sometimes, JS libaries can interfere with your desired results. I can't speak for Chosen JS library, but inspect the markup and see how it renders. As long as it still has the listbox on the client (it must have some input element defined somewhere; my guess it hides it and updates the values as they are selected), then yes it should integrate fine.
However, when the controller posts back, you have to repopulate the Model.SelectedCompanies property with whatever values came back from the POST operation to the controller. The property should still have the selected companies if you return a View from the POST operation. If you are using a RedirectToAction instead, you'd have to store the selections in TempData.
I've faced with the issue with Vaasin's Combobox. I'd like to allow the user be able as select existed item from the list same provide his own value typing in the text field. I thought that it has to be easy, but... What I have now is
ComboBox roles = new ComboBox();
roles.setInputPrompt("Select Role");
roles.addItems(userService.getAllRoles());
roles.setImmediate(true);
roles.setNullSelectionAllowed(false);
roles.setNewItemsAllowed(true);
formLayout.addComponent(roles);
Here I've found that setNewItemsAllowed allows such behavior, but for some reason it doesn't work for me. When I start typing some new value I can see an empty drop-down and when I select another field the value in checkbox reverts to prompt text.
It is not enough to allow new items in the ComboBox.
You must alos set the new item handler, until you do so, the ComboBox has no way to know what a new item should look like.
roles.setNewItemHandler(....your handler....);
Example code and the Docu for it.
I´m using the SelectItem component with configuration:
private SelectItem nElementsCombo;
nElementsCombo = new SelectItem();
nElementsCombo.setMultiple(true);
nElementsCombo.setMultipleValueSeparator("|");
In the combo the elements selected are shown item_selected_1|item_selected_2|item_selected_3
but when I do:
nElementsCombo.getValueAsString()
Return item_selected_1,item_selected_2,item_selected_3 and I´d like item_selected_1|item_selected_2|item_selected_3
How can I solve this?
from the javadoc :If this item is displaying multiple values, this property will be the string that separates those values for display purposes. Display purpose
I don't catch it, can you replace in your returned string the comma by the pipe ..... !!!
As per Alain's answer, MultipleValueSeparator is only for display purpose.
Means, when you select multiple values from picklist & then when the picklist is hidden on blur (focus lost) of multi select item, the selected values are displayed as a string separated by comma(default). This display can be changed by MultipleValueSeparator. But not the one you get by multiSelectItem.getValueAsString().
Also I don't think, there's any provision in SmartGWT API which fulfills your requirement, as of now.
I need solution for my problem on urgent basis, I am new with mvc, knockout please provide me sample code for my problem. any help will be highly appreciated.
suppose I have an observable array in my viewmodel i.e
var viewmodel = {
vendorproviders : ko.observablearray([])
}
where vendorproviders list consist of multiple attributes like id, name, country, address etc
I want to populate that array in my grid where each row will have a select button, when that button is clicked it should post the id to my controller action either by submitting or by ajax call.
Furthor more that grid should be searchable like if there is a separate text box, based on the value of text box grid should display matching providers else display all providers.
when user search for particular provider grid should populate from observable array instead of making call at server again and again to pupulate the observable array.
I would suggest starting here.
http://learn.knockoutjs.com/#/?tutorial=intro
What you are talking about is all the basic functionality of the tools you referenced.
I have a SelectItem which I fill through a Map that has this combo is within a listgridfield, so good up there, but when I select any item in the combobox instead of get the description or value of the map puts the key in the listgridfield.
How I can do to make me set the value instead of key? now I tried to do with AddChangeHandler but has not worked.
I got the next code:
final ListGridField measureField = new ListGridField(CdmsConstants.MEASURE_ABB, CdmsConstants.CMB_MEASURE_TITULO, 100);
final SelectItem measureComboBox = new SelectItem();
measureComboBox.setDefaultToFirstOption(false);
measureComboBox.setName(CdmsConstants.MEASURE_ABB);
measureComboBox.setTitle(CdmsConstants.CMB_MEASURE_TITULO);
measureComboBox.setDefaultValues(CdmsConstants.CMB_DEFAULT_VALUE);
measureComboBox.setType("comboBox");
measureComboBox.setVisible(true);
measureComboBox.setValueMap(result);
measureComboBox.setValidateOnExit(true);
measureField.setEditorType(measureComboBox);
In the measureComboBox When i put the variable result (that is a Map) and click to any item of the combo the value that shows into the combo box is the key of the linckedhashmap and no the value of the item... how can i make to change this?
Thanks a lot.
If you use a datasource instead of LinkedHashMap, then you can use setValueField method of SelectItem instance. but in this case MAY you can use setValueFormatter method of your SelectItem object.
I had the same/similar problem, my solution that can be seen here ListGrid.setEditorCustomizer in SmartGWT was to use a datasource for the SelectItem and then implemented my own CellFormatter