Я был неправ. Он работает только для combobox, по моему сводному ящику находится в ячейке сетки. Я пытаюсь установить значение выпадающего списка, точно так же, как обычно, но doent поработаем на выпадающий список в сетке:/
Это целый кусок кода
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);
Что я делаю неправильно ?
Что вы пытаетесь сделать? Вы пытаетесь установить значение по умолчанию? вы можете получить доступ к выбранному значению с помощью «event.getSelectedItem()». – nayakam
Посмотрите на мое сообщение ниже. – piechos