简体   繁体   English

Sencha gxt,在组合框中设置值

[英]Sencha gxt, set value in combobox

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 我正在使用sencha gxt 3.0

请改用comboBox.addValueChangeHandler(...)。

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? 我究竟做错了什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM