2012-05-16 50 views
0

是否可以使用複選框支持的Dojo dgrid窗口小部件(與數據存儲相對)來選擇行?使用Dojo dgrid與沒有存儲的選擇器列插件?

我成功地啓動了一個基本的數組備份dgrid,然後添加了Selection mixin以啓用行選擇。所以現在我有一個由數組支持並允許行選擇的dgrid。但是,當我嘗試通過selector column plugin添加複選框時,出現以下錯誤:this.store is undefined.

我確定this.store用於標識選擇哪些行:有多次調用this.store.getIdentity(rowObject)方法,它直接關聯查詢網格選擇時返回的結果。

當使用對象數組而不是存儲時,是否可以指定某個列字段來標識所選行?在我的代碼下面的WORKAROUND_STORE有效地做到了這一點,但也許我錯過了一個簡單的解決方案,如設置一些屬性,如:selector({idProperty: 'col1'}).它似乎應該更容易做到。

require(["dgrid/Grid", 
     "dgrid/selector", 
     "dgrid/Selection", 
     "dojo/_base/declare"], 
    function(Grid, selector, Selection, declare){ 

     var columns = { 
      col1: selector({}), 
      col2: {label: 'COL2'}, 
      col3: {label: 'COL3'}, 
     }; 

     var data = [ 
      { col1: '1', col2: 'A', col3: 'I'}, 
      { col1: '2', col2: 'B', col3: 'II'}, 
      { col1: '3', col2: 'C', col3: 'III'} 
     ]; 

     WORKAROUND_STORE = { 
      getIdentity: function(item) { return item.col1 } 
     } 

     var SelectionGrid = declare([Grid, Selection]); 
     window.methodGrid = new SelectionGrid({ 
      store: WORKAROUND_STORE, 
      columns: columns, 
      selectionMode: "none", 
      allowSelectAll: true 
     }, "methodGridDiv"); 
     window.methodGrid.renderArray(data); 
    } 
); 

回答

4

這裏是我落得這樣做:我裹在道場存儲器中存儲我的數據陣列,其具有接受新的數據陣列中的setData()方法。主要變化:

  • 使用OnDemandGrid而不是電網
  • 裹數據在道場內存存儲對象
  • 更新網格的商店陣列的數據更新
  • 呼叫網格的刷新方法的陣列( )

全碼:

require(["dgrid/OnDemandGrid", 
     "dgrid/selector", 
     "dgrid/Selection", 
     "dojo/_base/declare", 
     "dojo/store/Memory"], 
    function(OnDemandGrid, selector, Selection, declare, Memory){ 

     var columns = { 
      col1: selector({}), 
      col2: {label: 'COL2'}, 
      col3: {label: 'COL3'}, 
     }; 

     var data = [ 
      { col1: '1', col2: 'A', col3: 'I'}, 
      { col1: '2', col2: 'B', col3: 'II'}, 
      { col1: '3', col2: 'C', col3: 'III'} 
     ]; 

     var SelectionGrid = declare([OnDemandGrid, Selection]); 
     window.methodGrid = new SelectionGrid({ 
      store: Memory({idProperty: 'methodId'}), 
      columns: columns, 
      selectionMode: "none", 
      allowSelectAll: true 
     }, "methodGridDiv"); 
     window.methodGrid.store.setData(data); 
     window.methodGrid.refresh(); 
    } 
); 

更新響應於:

Did you actually get checkboxes in there? I don't see that in your code snippets.

的代碼,增加了複選框是:col1: selector({})。或者更明確地說:col1: selector({selectorType: 'checkbox'})

請注意選擇器插件是另一個column plugin,其工作方式與編輯器插件不同。