2012-07-03 43 views
1

這是我的問題:在我的應用程序中,我有一個Dojo EnhancedGrid,由一個ItemFileReadStore備份。頁面流程如下所示:Dojo EnhancedGrid和編程選擇

  1. 用戶從選擇列表中選擇一個值。
  2. 將列表中的項目發佈到服務器上,然後使用服務器中的數據更新網格(不要問爲什麼,這是應該如何工作的)
  3. 新項目在網格中突出顯示。

現在,前兩步工作就像一個魅力;然而,第三步讓我感到頭痛。所述數據被成功地發送到服務器後(通過dojo.xhrPost())下面的代碼運行:

myGrid.store.close(); 
myGrid._refresh(); 
myGrid.store.fetch({ 
    onComplete : function(items) { 
     for (var i = 0; i < items.length; i++) { 
      if (items[i].documentType[0].id == documentTypeId) {            
       var newItemIndex = myGrid.getItemIndex(items[i]); 
       exportMappingGrid.selection.deselectAll(); 
       exportMappingGrid.selection.addToSelection(newItemIndex); 
      } 
    } 
     } 
    }); 

現在,網格的選擇被更新(即,選擇對象具有的selectedIndex> 0),但在視覺上沒有反應,除非我將鼠標懸停在「選定」行上。如果我刪除.deselectAll()行(我懷疑是罪魁禍首),那麼有時我最終會選中兩個項目,儘管網格選擇模式屬性設置爲單個

對此有何看法?

非常感謝。

回答

0

您需要使用的setSelected(),像這樣

exportMappingGrid.selection.setSelected(newItemIndex, true); 

第二個參數是真正的以選擇該行,假以取消選擇它。

+0

我用的setSelected和它似乎工作得很好,直到我遇到了一些麻煩:如果我在網格中選擇一行(通過點擊鼠標),然後添加另一行並選擇它programmaticaly我結束了兩個選定的行。 –

+0

在類似的情況下,我發現我必須做setSelected(xxx,false)以在programmaticaly選擇新行之前取消選擇舊行。 –

0

這對我來說是什麼在起作用:

grid.selection.clear(); 
grid.selection.addToSelection(newItemIndex); 
grid.selection.getFirstSelected(); 

喬恩

+0

但這個作品也是: grid.selection.clear(); grid.selection.setSelected(newItemIndex,true); –