PDA

View Full Version : Problem with setting value in combobox



piechos
25 Feb 2015, 4:38 AM
Hey, I'm trying to set value in the combobox but it doesn't work for me. I'm trying to it this way:



sortingStore = new ListStore<String>(modelKeyProvider);
sortingStore.add("Value 1");
sortingStore.add("Value 2");
ComboBox<String> combobox2 = new ComboBox<String>(sortingStore,
new LabelProvider<String>() {

@Override
public String getLabel(String item) {
return item;
}
});
combobox2.addSelectionHandler(new SelectionHandler<String>() {

@Override
public void onSelection(SelectionEvent<String> event) {
ComboBox<String> combo = (ComboBox<String>) event.getSource();
combo.setValue("Other Value");
}
});




After I change value in the combobox, nothing is happening. Does anyone know why?
I'm using sencha gxt 3.0

piechos
26 Feb 2015, 12:24 AM
I was wrong. It works for just a combobox, by my combobox is in the cell of the grid. I trying to set the value of the combobox, the same way as usual, but it doent's work for combobox in the grid :/
This is the whole piece of code

typeStore = new ListStore<String>(modelKeyProvider); typeStore.add("Category"); typeStore.add("Source"); typeStore.add("Author"); typeStore.add("Publication"); sortingStore = new ListStore<String>(modelKeyProvider); sortingStore.add("Ascending"); sortingStore.add("Descending"); ContentPanel panel = new ContentPanel(); panel.setHeadingText("Categories sorting"); panel.setBodyStyle("background-color: #E7EEF9"); final ColumnConfig<GridElement, String> cc1 = new ColumnConfig<GridElement, String>( properties.groupType(), 150, "GroupType"); ColumnConfig<GridElement, String> cc2 = new ColumnConfig<GridElement, String>( properties.sorting(), 150, "Sorting"); List<ColumnConfig<GridElement, ?>> list = new ArrayList<ColumnConfig<GridElement, ?>>(); list.add(cc1); list.add(cc2); ColumnModel<GridElement> columnModel = new ColumnModel<GridElement>( list); Grid<GridElement> grid = new Grid<GridElement>( (ListStore<GridElement>) mainStore, columnModel); final GridInlineEditing<GridElement> editing = new GridInlineEditing<GridElement>( grid); ComboBox<String> combobox1 = new ComboBox<String>(typeStore, new LabelProvider<String>() { @Override public String getLabel(String item) { return item; } }); combobox1.setTriggerAction(TriggerAction.ALL); combobox1.setEditable(false); editing.addEditor(cc1, combobox1); final ComboBox<String> combobox2 = new ComboBox<String>(sortingStore, new LabelProvider<String>() { @Override public String getLabel(String item) { return item; } }); combobox2.setTriggerAction(TriggerAction.ALL); combobox2.setEditable(false); combobox2.setAutoValidate(true); editing.addEditor(cc2, combobox2); editing.setClicksToEdit(ClicksToEdit.TWO); editing.addCompleteEditHandler(new CompleteEditHandler<GridElement>() { @Override public void onCompleteEdit(CompleteEditEvent<GridElement> event) { int col = event.getEditCell().getCol(); int row = event.getEditCell().getRow(); String value = (String) ((ComboBox<Object>) editing .getEditor(event.getSource().getEditableGrid() .getColumnModel().getColumn(col))).getValue(); if (col == 0) { mainStore.get(row).setGroupType(value); } else { mainStore.get(row).setSorting(value); } if(mainStore.get(row).getGroupType().equals(i18n.ordering_category())) { mainStore.get(row).setSorting("Custom"); ((ComboBox<Object>) editing .getEditor(event.getSource().getEditableGrid() .getColumnModel().getColumn(col))).setValue("Custom"); } } }); grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); grid.setWidth(302); grid.setHeight(300); grid.setBorders(true); VerticalLayoutContainer vLayout = new VerticalLayoutContainer(); vLayout.add(createToolbar(grid, editing), new VerticalLayoutData(-1, 27)); CenterLayoutContainer cLayout = new CenterLayoutContainer(); cLayout.add(grid); vLayout.add(cLayout, new VerticalLayoutData(1, 1)); panel.add(vLayout);What am I doing wrong?