2014-05-12 80 views
0

我正在使用smartgwt(不是付費的許可證版本),並且我有一個包含三個條目的listgrid。 鍵,值,重置。刪除記錄,然後立即取回

重置字段是一個按鈕,應該重置對該值的任何更改,這裏是我奮鬥的地方。 我試圖實現它那樣簡單

@Override 
public void onClick(ClickEvent event) 
{ 
    DataSource ds = this.grid.getDataSource(); 
    ds.removeData(record); 
    ds.fetchData(); 
    this.grid.redraw(); 
} 

電網是我ListGrid並記錄已單擊先復位行。

但是這隻能刪除條目,如果我重新加載(即使使用正確的值,因爲這是我的服務器如果獲取刪除請求時會執行的操作),它仍會在那裏,但我希望它在那之後立即出現我點擊按鈕,而不是點擊了一下後。

我認爲fetchData和重繪請求結合起來可以實現這個功能。

編輯:好一些更多的代碼,這顯示了我的ListGrid和RevertButton的構造函數,它應該刪除並再次添加記錄。

private static final String REVERT_NAME = "revertField"; 

    public MyListGrid(final String name) 
    { 
     this.setDataSource(PropertyListDS.getInstance(name); 

     ListGridField keyField = new ListGridField(ConfigurationDataSourceFields.PROPERTY_NAME, "Property"); 
     ListGridField valueField = new ListGridField(ConfigurationDataSourceFields.PROPERTY_VALUE, "Value"); 
     ListGridField revertField = new ListGridField(REVERT_NAME, "Revert to Default"); 

     valueField.setCanEdit(true); 

     this.setShowRecordComponents(true);   
     this.setShowRecordComponentsByCell(true); 

     this.setAutoFetchData(true); 

     this.setFields(keyField, valueField, revertField); 
    } 

    @Override 
    protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) 
    { 
     String fieldName = this.getFieldName(colNum); 
     Canvas canvas = null; 
     if (REVERT_NAME.equals(fieldName)) 
     { 
      canvas = new RevertButton(this, record); 
     } 
     return canvas; 
    } 

    private class RevertButton extends IButton implements ClickHandler 
    { 
     private final MyListGrid grid; 
     private final ListGridRecord record; 

     public RevertButton(final MyListGrid grid, final ListGridRecord record) 
     { 
      super(); 
      this.setTitle("Revert to Default"); 
      this.grid = grid; 
      this.record = record; 
      this.addClickHandler(this); 
     } 

     @Override 
     public void onClick(ClickEvent event) 
     { 
      DataSource ds = this.grid.getDataSource(); 
      ds.removeData(record); 
      ds.fetchData(); 
      this.grid.redraw(); 
     } 
    } 
+0

根據我的理解,從客戶端作品中刪除,但在服務器端沒有更改? –

+0

它工作在兩端,只是不是我想要的;)客戶端沒有看到變化,直到他在ui中點擊了一下就是問題所在。 – Nozdrum

+0

所以你的意思是你有時間差距?潛伏 ? –

回答

2

用這種方式使用DSCallback

DataSource#removeData()是對服務器的異步調用。重新繪製網格,或者在從服務器獲得該記錄已在DSCallback中刪除的響應後再次獲取數據。

DataSource dataSource = grid.getDataSource(); 
dataSource.removeData(record,new DSCallback() { 

    @Override 
    public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest){ 
     Record[] records=dsResponse.getData();//deleted records 

     grid.fetchData();//fetch data again 
    } 
}); 

請在這個線程看看Removing local record from listGrid without committing

再次獲取數據之前ListGrid#saveAllEdits()嘗試。

您可以使用ListGrid#removeSelectedData()嘗試從該組件中刪除當前選定的記錄。如果這是一個數據綁定網格,記錄將直接從數據源中刪除。