Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGridEditorCustomizer and alwaysShowEditors(true)

    Using the new ListGridEditorCustomizer and ListGrid.setAlwaysShowEditors(true) doesn't work.
    If you select a cell for editing, all other cells in the grid will show the same editor as the one for the selected cell.
    Following is a sample code, taken from the ListgridEditorCustomizer sample and setting the countryGrid.setAlwaysShowEditors(true):
    Code:
    package selectrow.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.types.ListGridEditEvent;
    import com.smartgwt.client.types.MultipleAppearance;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.fields.CheckboxItem;
    import com.smartgwt.client.widgets.form.fields.DateItem;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.PasswordItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.SliderItem;
    import com.smartgwt.client.widgets.form.fields.SpinnerItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.validator.CustomValidator;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridEditorContext;
    import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import java.util.Date;
    
    public class MainEntryPoint implements EntryPoint {
    
        @Override
        public void onModuleLoad() {
            final ListGrid countryGrid = new ListGrid();
            countryGrid.setWidth(300);
            countryGrid.setHeight(340);
            countryGrid.setShowAllRecords(true);
            countryGrid.setAlwaysShowEditors(true);
    
            ListGridField nameField = new ListGridField("name", "Name", 120);
            nameField.setCanEdit(false);
    
            ListGridField valueField = new ListGridField("value", "Value Field", 170);
    
            countryGrid.setFields(nameField, valueField);
    
            countryGrid.setData(getData());
            countryGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
                @Override
                public FormItem getEditor(ListGridEditorContext context) {
                    ListGridField field = context.getEditField();
                    if (field.getName().equals("value")) {
                        NameValueRecord record = (NameValueRecord) context.getEditedRecord();
                        int id = record.getID();
                        switch (id) {
                            case 1:
                                TextItem textItem = new TextItem();
                                textItem.setShowHint(true);
                                textItem.setShowHintInField(true);
                                textItem.setHint("Some Hint");
                                return textItem;
                            case 2:
                                return new PasswordItem();
                            case 3:
                                return new DateItem();
                            case 4:
                                CheckboxItem cbi = new CheckboxItem();
                                cbi.setShowLabel(false);
                                return cbi;
                            case 5:
                                final SpinnerItem spinnerItem = new SpinnerItem();
                                spinnerItem.setMin(-10);
                                spinnerItem.setMax(10);
                                spinnerItem.setStep(1);
                                spinnerItem.setValidators(new CustomValidator() {
                                    @Override
                                    public boolean condition(Object value) {
                                        SC.logWarn("condition: " + spinnerItem.getEnteredValue());
                                        return false;
                                    }
                                });
                                spinnerItem.setValidateOnExit(true);
                                return spinnerItem;
                            case 6:
                                SelectItem selectItemMultipleGrid = new SelectItem();
                                selectItemMultipleGrid.setShowTitle(false);
                                selectItemMultipleGrid.setMultiple(true);
                                selectItemMultipleGrid.setMultipleAppearance(MultipleAppearance.PICKLIST);
                                selectItemMultipleGrid.setValueMap("Cat", "Dog", "Giraffe", "Goat", "Marmoset", "Mouse");
                                return selectItemMultipleGrid;
                            case 7:
                                SliderItem sliderItem = new SliderItem();
                                sliderItem.setMaxValue(10);
                                sliderItem.setWidth(160);
                                return sliderItem;
                            default:
                                return context.getDefaultProperties();
                        }
                    }
                    return context.getDefaultProperties();
                }
            });
    
            countryGrid.setCanEdit(true);
            countryGrid.setEditEvent(ListGridEditEvent.CLICK);
            countryGrid.setEditByCell(true);
    
            countryGrid.draw();
        }
    
        private ListGridRecord[] getData() {
            return new ListGridRecord[]{
                    new NameValueRecord(1, "String Editor", "some string"),
                    new NameValueRecord(2, "Password Editor", "donkeykong"),
                    new NameValueRecord(3, "Date Editor", new Date()),
                    new NameValueRecord(4, "Boolean Editor", Boolean.FALSE),
                    new NameValueRecord(5, "Spinner Int Editor", 5),
                    new NameValueRecord(6, "SelectItem Editor", "Dog"),
                    new NameValueRecord(7, "Slider Editor", 7)
            };
        }
        public static class NameValueRecord extends ListGridRecord {
    
            public NameValueRecord(int id, String name, Object value) {
                setID(id);
                setName(name);
                setValue(value);
            }
    
            public final void setID(int id) {
                setAttribute("ID", id);
            }
    
            public int getID() {
                return getAttributeAsInt("ID");
            }
    
            public final void setValue(Object value) {
                setAttribute("value", value);
            }
    
            public Object getValue() {
                return getAttributeAsObject("value");
            }
    
            public final void setName(String name) {
                setAttribute("name", name);
            }
    
            public String getName() {
                return getAttribute("name");
            }
    
        }
    
    }
    I'm using SmartGWT 2.5 and GWT 2.3

    #2
    These features were not designed to work with each other. We'll make that clear in the docs.

    Comment


      #3
      that's a pitty! Any chance to reconsider?

      Comment

      Working...
      X