Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

ListGrid.startEditingNew and canEditCell

$
0
0
Environment:
smartgwt-4.0p-2013-12-17

When editing a new list grid record with startEditingNew(defaultValues), the default values are not provided any more in
Code:

protected boolean canEditCell(int rowNum, int colNum) {
Record record = getEditedRecord(rowNum);
}

This worked at least until 3.0p-2013-01-08.
Now canEditCell seems first to be invoked with an empty record and then again with the record containing the default values.
I have expected that before canEditCell is invoked, the new record is populated with the default values.
Has this been intentionally changed or is this a bug?

Example, drawn from the showcase "grid_editing_new_row"
Code:

@Override
    public void onModuleLoad() {
        Canvas canvas = new Canvas();
        final ListGrid countryGrid = new ListGrid() {
            @Override
            protected boolean canEditCell(int rowNum, int colNum) {
                Record editedRecord = getEditedRecord(rowNum);
                ListGridField f = this.getField(colNum);
                System.out.println("Row/Col=" + rowNum + "/" + colNum +  ", Fname=" + f.getName() + ", EditedRecord.countryName=" + editedRecord.getAttribute("countryName"));
                return super.canEditCell(rowNum, colNum);
            }
        };
        countryGrid.setWidth(550);
        countryGrid.setHeight(224);
        countryGrid.setShowAllRecords(true);
        countryGrid.setCellHeight(22);
        countryGrid.setID("countryList");
        countryGrid.setDataSource(CountryXmlDS.getInstance());

        ListGridField nameField = new ListGridField("countryName", "Country");
        countryGrid.setFields(nameField);

        countryGrid.setAutoFetchData(true);
        countryGrid.setCanEdit(true);
        countryGrid.setEditEvent(ListGridEditEvent.CLICK);
        countryGrid.setListEndEditAction(RowEndEditAction.NEXT);
        canvas.addChild(countryGrid);

        IButton button = new IButton("Edit New");
        button.setTop(250);
        button.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("countryName", "whatever");
                countryGrid.startEditingNew(map);
            }
        });
        canvas.addChild(button);

        canvas.draw();
    }

    public static class CountryXmlDS extends DataSource {

        private static CountryXmlDS instance = null;

        public static CountryXmlDS getInstance() {
            if (instance == null) {
                instance = new CountryXmlDS("countryDS");
            }
            return instance;
        }

        public CountryXmlDS(String id) {

            setID(id);
            setRecordXPath("/List/country");
            DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
            pkField.setHidden(true);
            pkField.setPrimaryKey(true);

            DataSourceTextField countryNameField = new DataSourceTextField("countryName", "Country");
            countryNameField.setRequired(true);

            setFields(pkField, countryNameField);

            setClientOnly(true);
        }
    }

Output when editing a new record:
Code:

Row/Col=0/0, Fname=countryName, EditedRecord.countryName=null
Row/Col=0/0, Fname=countryName, EditedRecord.countryName=whatever
Row/Col=0/0, Fname=countryName, EditedRecord.countryName=whatever


Viewing all articles
Browse latest Browse all 4756

Trending Articles