1. #1
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Zurich, Switzerland
    Posts
    20
    Vote Rating
    0
    jack83 is on a distinguished road

      0  

    Default Grid with Comboboxes - controlling the content of the comboboxes in the same row

    Grid with Comboboxes - controlling the content of the comboboxes in the same row


    I built a Grid which contains multiple columns with ComboBoxCell objects only. I have the following problem. I want to change the content of the combobox in the second column, if I change the value in the first row.
    But it should work only for the current row, not for the whole grid. By default the comboboxes of the second row are inactive (read-only), if I select in the first combo box a value other than PublicationLevel.PRIVATE, the values in the second combo box should be set.

    Here is how I declare them.

    Code:
        
    ColumnConfig<PublicationPolicyDto, PublicationLevel> publicationLevelCol;
    ColumnConfig<PublicationPolicyDto, KeyValueObject<Integer, String>> publStructureMainCol;
    The PublicationPolicyDto is my class with data, the PublicationLevel is a java enum for the first combobox column. KeyValueObject is a key - value pair class for the second combo box column

    The first column is instantiated by the following method call, which is appropriately parametrized.
    Code:
    private <T extends Enum<T>> ColumnConfig<PublicationPolicyDto, T> createComboBoxColumn(ListStore<T> dataStore, int width, String name, SelectionHandler<T> selHandler,
            ValueProvider<PublicationPolicyDto, T> prop, LabelProvider<T> lblProv) {
            ColumnConfig<PublicationPolicyDto, T> column = new ColumnConfig<PublicationPolicyDto, T>(prop, width, name);
    
            ComboBoxCell<T> cmbCell = new ComboBoxCell<T>(dataStore, lblProv);
    
            cmbCell.addSelectionHandler(selHandler);
            cmbCell.setForceSelection(true);
            cmbCell.setAllowBlank(false);
            cmbCell.setTriggerAction(TriggerAction.ALL);
            column.setCell(cmbCell);
            return column;
        }
    This method creates the second combobox column.

    Code:
    private ColumnConfig<PublicationPolicyDto, KeyValueObject<Integer, String>> createComboBoxColumnGen(ListStore<KeyValueObject<Integer, String>> store, int width, String header,
            SelectionHandler<KeyValueObject<Integer, String>> selHandler, ValueProvider<PublicationPolicyDto, KeyValueObject<Integer, String>> prop) {
    
            ColumnConfig<PublicationPolicyDto, KeyValueObject<Integer, String>> column = new ColumnConfig<PublicationPolicyDto, KeyValueObject<Integer, String>>(prop, width, header);
    
            ComboBoxCell<KeyValueObject<Integer, String>> cmbCell = new ComboBoxCell<KeyValueObject<Integer, String>>(store, new LabelProvider<KeyValueObject<Integer, String>>() {
                @Override
                public String getLabel(KeyValueObject<Integer, String> item) {
                    return item.getValue();
                }
            });
            cmbCell.addSelectionHandler(selHandler);
            cmbCell.setForceSelection(true);
            cmbCell.setTriggerAction(TriggerAction.ALL);
            cmbCell.setReadOnly(true);
            column.setCell(cmbCell);
    
            return column;
        }
    Here is my selection handler for the first column. It should simply unlock the combobox in the second column but only in the same row, not in the whole column.

    Code:
    public SelectionHandler<PublicationLevel> createSelHandlerForPublicationLevel() {
            SelectionHandler<PublicationLevel> sel = new SelectionHandler<PublicationLevel>() {
    
                @Override
                public void onSelection(SelectionEvent<PublicationLevel> event) {
                    
                    ComboBoxCell<KeyValueObject<Integer, String>> cmb = (ComboBoxCell<KeyValueObject<Integer, String>>) publStructureMainCol.getCell();
                    if (event.getSelectedItem().getIndex() == PublicationLevel.PRIVATE.getIndex()) {
                        cmb.getStore().clear();
                        cmb.setReadOnly(true);
                    } else {
                        if (cmb.isReadOnly()) {
                            cmb.setReadOnly(false);
                            // change the content of the second combo box, but only for the same row
                            setInitStructureMain(0);
                        }
                    }
                }
            };
            return sel;
        }
    Here is how I set the data in the combo box. I simply modify the store but it affects the whole column of the combo boxes, not a single combo box.

    Code:
    private void setInitStructureMain(int structureMainId) {
            ArrayList<KeyValueObject<Integer, String>> newList = publicationStructureMain.get(LocaleInfo.getCurrentLocale().getLocaleName().toLowerCase());
            if (newList == null) {
                newList = publicationStructureMain.get("de");
            }
            publStructMainStore.clear();
            publStructMainStore.add(new KeyValueObject<Integer, String>(0, ""));
    
            for (int i = 0; i < newList.size(); i++) {
                publStructMainStore.add(newList.get(i));
            }
            KeyValueObject<Integer, String> currVal = null;
            for (KeyValueObject<Integer, String> kv : publStructMainStore.getAll()) {
                if (kv.getKey() != null && kv.getKey().intValue() == structureMainId) {
                    currVal = kv;
                    break;
                }
            }
    
            ComboBoxCell<KeyValueObject<Integer, String>> c = (ComboBoxCell<KeyValueObject<Integer, String>>) publStructureMainCol.getCell();
            c.select(currVal);
        }
    Is there any way I could reload the content of the second column's combo box, but only in the current row, not for the whole column?

  2. #2
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Zurich, Switzerland
    Posts
    20
    Vote Rating
    0
    jack83 is on a distinguished road

      0  

    Default


    I will try to explain my problem again without going into implementation details.

    Let's say I have got a cell grid like the one from the http://www.sencha.com/examples/explo...Place:cellgrid

    Let's say I would like to change the content of the light column combo box (its store) if the selected colour changes. I mean the store of the combobox in the given row should depend on the selected color in this row.

    Is there any way to achieve such a behavior? I tried to change the store of the cell but then all the combo boxes in the column were affected, not only the particular one I wanted to.

  3. #3
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Zurich, Switzerland
    Posts
    20
    Vote Rating
    0
    jack83 is on a distinguished road

      0  

    Default


    To keep it very simple.

    How can I get the cell of the given column and row? Is it possible at all? I always get the cell of the whole column but this is not what I want.

Tags for this Thread