2013-01-11 29 views
0

我正在使用GXT 3來構建一個將顯示「事件」的GridView。如何在顯示時自動檢查gridview中的複選框?

我想要做的是,當它呈現它時,我想根據數據庫中的布爾值檢查一些複選框,其他複選框爲空。

下面你有我的代碼:

 CheckBoxSelectionModel<IncidentDto> isIncidentCM = new CheckBoxSelectionModel<IncidentDto>(incidentProperties.incident()); 
     allColumns.add(isIncidentCM.getColumn()); 
     ColumnModel<IncidentDto> columnModel = new ColumnModel<IncidentDto>(allColumns); 

     final Grid<IncidentDto> grid = new Grid<IncidentDto>(store, columnModel); 
     grid.setSelectionModel(isIncidentCM); 
     add(grid); 

而且IncidentProperties值提供商:

IdentityValueProvider<IncidentDto> incident(); 

回答

1

我不知道你是否能綁定選擇值布爾屬性,但你可以將一個偵聽器添加到Grid中以根據布爾條件更新複選框。

grid.addBeforeShowHandler(BeforeShowEvent event) { 
    @Override 
    public void onBeforeShow(BeforeShowEvent event) { 
    List<IncidentDto> itemsToSelect = new ArrayList<IncidentDto>(); 
    for (IncidentDto incident : store.getAll()) { 
     if (incident.getBooleanProperty()) { //whatever your property is called 
     itemsToSelect.add(incident); 
     } 
    } 
    isIncidentCM.setSelection(itemsToSelect); 
    } 
} 

有可能是在使用BeforeShowEvent取決於如何/當你填入你的商店,使電網等,但假設你的店是全負荷並且性能可從您的存儲對象等方面的影響,我相信這應該完成你的目標。

相關問題