2012-04-26 53 views

回答

2

https://github.com/SitePen/dgrid/blob/master/demos/dTuned/index.html的示例中,通過使用mixin創建網格。

window.grid = new (declare([Grid, Selection, Keyboard, Hider]))({ 
    ... 
}, "grid"); 

選擇混入具有以下屬性:

// selection: 
//  An object where the property names correspond to 
//  object ids and values are true or false depending on whether an item is selected 
selection: {}, 
+0

我的問題是關於dgrid(gridFromHtml)(參考文獻:https://github.com/SitePen/dgrid),而不是有關的DataGrid DojoX中。上述方法不適用於dgrid。 – TechnoCrat 2012-04-26 10:41:47

+0

我的錯誤。我以前沒有使用過這些小部件。但快速查看代碼,我更新了我的答案。希望這可以幫助。 – 2012-04-26 11:52:04

+1

您如何獲得特定單元格的選擇而不是整行? – MozenRath 2012-05-08 07:47:28

1

可以,例如,實現到返回選定的細胞的方法,使用select屬性並從電網cell()方法。

getSelectedCells: function() { 
    var cell, 
     results = []; 

    for (var rowIdx in grid.selection) { 
    for (var colIdx in grid.selection[rowIdx]) { 
     cell = grid.cell(rowIdx, colIdx); 
     results.push(cell); 
    } 
    } 

    return results; 
} 
0

您應該使用CellSelection mixin

選定細胞可通過selection對象或內部dgrid-selectdgrid-deselect事件由其cells屬性進行訪問。

從混入的文檔:

選擇對象存儲的嵌套的散列,其中外散列是由項目ID和內散列通過柱ID鍵控鍵控。

dgrid-select和dgrid-deselect事件仍會觸發,但包含一個單元格屬性,其中包含單元格對象數組而非行屬性。