Announcement

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

  • Record foreign value not cleared while mass editing grid

    Hi,

    There is a editable grid without auto save, so editing multiple rows is possible. The grid's field editorType is ComboBox. Additionally, grid's field displayField is set to other hidden field containing code name as described here: https://www.smartclient.com/smartcli...tionDataSource for performance reasons.

    Code:
    package pl.com.tech4.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.OperationBinding;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.DSOperationType;
    import com.smartgwt.client.types.DSProtocol;
    import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    
    public class MainEntryPoint implements EntryPoint {
    
        public void onModuleLoad() {
    
            layout();
        }
    
        private void layout() {
    
            DataSource employmentDS = new DataSource();
            employmentDS.setID("Employment");
            OperationBinding fetchBinding = new OperationBinding();
            fetchBinding.setOperationType(DSOperationType.FETCH);
            fetchBinding.setDataFormat(DSDataFormat.XML);
            fetchBinding.setDataProtocol(DSProtocol.POSTXML);
            employmentDS.setOperationBindings(fetchBinding);
            employmentDS.setDataURL("Employment.xml");
    
            DataSource departmentDS = new DataSource();
            departmentDS.setID("Department");
            departmentDS.setOperationBindings(fetchBinding);
            departmentDS.setDataURL("Department.xml");
    
            DataSourceField idDepField = new DataSourceField();
            idDepField.setName("id");
            idDepField.setPrimaryKey(true);
            idDepField.setHidden(true);
            DataSourceTextField codeField = new DataSourceTextField();
            codeField.setName("code");
            departmentDS.setFields(idDepField, codeField);
    
            DataSourceField idField = new DataSourceField();
            idField.setName("id");
            idField.setPrimaryKey(true);
            idField.setHidden(true);
            DataSourceField employerField = new DataSourceField();
            employerField.setName("employer");
            employerField.setForeignKey("Department.id");
            employerField.setValueXPath("employer/id");
            ComboBoxItem defaultItem = new ComboBoxItem("employer");
            defaultItem.setOptionDataSource(departmentDS);
            defaultItem.setValueField("id");
            defaultItem.setDisplayField("code");
            defaultItem.setPickListFields(new ListGridField("id"), new ListGridField("code"));
            employerField.setEditorProperties(defaultItem);
            DataSourceTextField employerCodeField = new DataSourceTextField("employer_code");
            employerCodeField.setValueXPath("employer/code");
            employerCodeField.setHidden(true);
            employmentDS.setFields(idField, employerField, employerCodeField);
    
            ListGridField employerLGF = new ListGridField("employer");
            employerLGF.setDisplayField("employer_code");
    
            ListGrid lg = new ListGrid();
            lg.setDataSource(employmentDS);
            lg.setFields(employerLGF);
            lg.setAutoFetchData(true);
            lg.setCanEdit(true);
            lg.setAutoSaveEdits(false);
            lg.draw();
        }
    
    }
    If you run above sample, enter edit mode in the first row and clear Employer field, then go to edit second row - you will see that just cleared value in the first row would be re-applied (but blue marked as modified).
    Click image for larger version

Name:	gridEditingProblem.gif
Views:	1
Size:	53.9 KB
ID:	256267

    Thanks,

    MichalG

    ps

    SmartClient Version: v12.0p_2018-08-20/LGPL Development Only (built 2018-08-20)

    Employment.xml

    Code:
    <response>
        <status>STATUS_SUCCESS</status>
        <startRow>0</startRow>
        <endRow>1</endRow>
        <totalRows>2</totalRows>
        <data>
            <Employment>
                <id>20</id>
                <employer>
                    <id>3</id>
                    <code>Microsoft</code>
                </employer>
            </Employment>
            <Employment>
                <id>21</id>
                <employer>
                    <id>4</id>
                    <code>Apple</code>
                </employer>
            </Employment>
        </data>
    </response>
    Department.xml

    Code:
    <response>
        <status>STATUS_SUCCESS</status>
        <startRow>0</startRow>
        <endRow>4</endRow>
        <totalRows>5</totalRows>
        <data>
            <Department>
                <id>1</id>
                <code>Oracle</code>
                <parentId>
                    <id>2</id>
                    <code>Sun</code>
                </parentId>
            </Department>
            <Department>
                <id>2</id>
                <code>Sun</code>
                <parentId>
                    <id>2</id>
                    <code>Sun</code>
                </parentId>
            </Department>
            <Department>
                <id>3</id>
                <code>Microsoft</code>
                <parentId>
                    <id>2</id>
                    <code>Sun</code>
                </parentId>
            </Department>
            <Department>
                <id>4</id>
                <code>Apple</code>
                <parentId>
                    <id>2</id>
                    <code>Sun</code>
                </parentId>
            </Department>
        </data>
    </response>

  • #2
    What's happening here is that you have successfully changed the value to blank, but the value in the displayField is unchanged. So the grid is showing the displayField value as usual, and is *correctly* showing the value as edited since the underlying value has been changed to blank.

    If this grid were configured with autoSaveEdits:true, there would have been a save to the server of the new blank value, and the returned data from the save could have been used to update the displayField. Since you've configured autoSaveEdits as false, you need to update the displayField yourself.

    This is covered in the docs under listGridField.optionDataSource, toward the end.

    Comment


    • #3
      Thanks.
      I understand that I am supposed to add changed handler like this one to cover case when user clears combo value:

      Code:
              ListGridField employerLGF = new ListGridField("employer");
              employerLGF.setDisplayField("employer_code");
              employerLGF.addChangedHandler(new ChangedHandler() {
                  @Override
                  public void onChanged(ChangedEvent event) {
                      ListGrid thisLG = ((ListGridField) event.getSource()).getListGrid();
                      Object value = event.getValue();
                      thisLG.setEditValue(event.getRowNum(), "employer_code", value);
                  }
              });
      MichalG

      Comment

      Working...
      X