smartgwt ListGridRecord以编程方式编辑问题

smartgwt ListGridRecord以编程方式编辑问题,gwt,smartgwt,Gwt,Smartgwt,我正在使用smartgwt,我有一个ListGrid,其中ListGridRecord中有一些填充的值。现在,如果我通过setAttribute(String fieldName,String value)以编程方式设置任何listGridRecord字段值,并通过listGridRecord.refreshFields()刷新该字段,那么这些值将反映到UI中。但问题是,如果我通过双击来编辑相同的ListGridRecord。然后该值将丢失或从UI中删除 class FieldRecord ex

我正在使用smartgwt,我有一个ListGrid,其中ListGridRecord中有一些填充的值。现在,如果我通过setAttribute(String fieldName,String value)以编程方式设置任何listGridRecord字段值,并通过listGridRecord.refreshFields()刷新该字段,那么这些值将反映到UI中。但问题是,如果我通过双击来编辑相同的ListGridRecord。然后该值将丢失或从UI中删除

class FieldRecord extends ListGridRecord{

private int id;
private String name;

public void setID(Long id) {
  setAttribute(Constant.ID, id);
 }

public void setName(String name) {
  setAttribute(Constant.NAME, name);
 }

public Long getID() {
  return getAttribute(Constant.ID);
 }

public String getName() {
   return getAttribute(Constant.NAME); 
 }
}


class testData {
  FieldDataSource fieldDS = new FieldDataSource();

  FieldRecord fieldRec = new FieldRecord();
  //set some default value of record.

  fieldDS.addData(fieldRec);
  FieldGrid fieldGrid = new FieldGrid();
  fieldGrid.setDataSource(fieldDS);

  public void parseValue(){
  // on some condition
   fieldRec.setAttribute(Constant.NAME, "high"); 
  // programmaticaly set record value and that value is removed when i double click on 
   that record. 
 }
}

我希望FieldGrid是一个ListGrid

应该使用设置字段将ListGridRecord附加到ListGrid

fieldGrid.setFields(fieldRec);
尝试将ListGrid/FieldGrid的autoSaveEdits设置为false

fieldGrid.autoSaveEdits(false);
将autoSaveEdits设置为false将创建一个“批量更新”/“批量删除”交互,在该交互中,所有编辑的单元格都将保留编辑(如果适用,跨行),直到调用ListGrid.saveEdits保存特定行,或调用ListGrid.saveAllEdits保存批处理中的所有更改

更新 对ListGrid使用addRowEditorExitHandler并显式设置新值,如下所示

       addRowEditorExitHandler(new RowEditorExitHandler() {

          @Override
          public void onRowEditorExit(final RowEditorExitEvent event) {
            if (event.getRecord() != null) {
              Record gridRecord = event.getRecord();
              //This will be an update operations
            }
            else {
              gridRecord = new Record();
              //This will be a new record creation
            }
            if (FieldGrid.this.validateRow(event.getRowNum())) {
              for (Object attribute : event.getNewValues().keySet()) {
                //Here you will be able to see all the newly edited values
                gridRecord.setAttribute(String.valueOf(attribute),  event.getNewValues().get(attribute));
              }
//Finally you will have a record with all unsaved values.Send it to server
              addData(gridRecord);
            }
          }
        });

嘿,谢谢你的回复。是的,fieldGrid指的是ListGrid。现在,当我进行autoSaveEdits(false)时,所有编程设置的值都将恢复到网格(值将保存到数据库),但对于我通过双击网格输入值的值(单元格可编辑),这些值不会被保存或反映(该值在UI上以蓝色显示)当我将listgrid记录对象发送到服务器进行持久化时。如果你需要更多的了解。请回答我。我将非常乐意提供进一步的细节。谢谢@arun。您是如何将listgridrecord发送到服务器端的。我使用了ListGid的addData方法。我已将smartgwt数据源机制与GWT rpc方法集成,以连接到服务器端。调试并查看您编辑的记录是否到达服务器端我已使用数据源绑定列表网格的所有记录。使用数据源的addData方法。我通过FieldGrid.getRecords()获取FieldGrid的所有编辑记录。当我调试getRecords()方法时,我无法看到双击编辑的更改。。。你让我开心。你的解决方案正好适合我的问题。现在已经解决了。再次感谢。热烈欢呼……)