1

我在我的 dojo 项目中使用 dgrid 组件。我有一个网格和一个按钮。我在网格上启用了单元格选择。

如何检索所选单元格的信息(数据)?我的用例是每当我单击按钮时,我应该能够获取与网格中选定单元格关联的数据。

我尝试在https://github.com/SitePen/dgrid/wiki/Components-Mixins查找文档,但找不到任何相关信息。

4

3 回答 3

2

https://github.com/SitePen/dgrid/blob/master/demos/dTuned/index.html的示例中,使用 mixins 创建了一个网格。

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

选择 mixin 具有以下属性:

// 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: {},
于 2012-04-26T10:18:01.733 回答
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;
}
于 2013-04-06T16:47:44.577 回答
0

您应该使用CellSelection mixin

选定的单元格可以通过selection对象或内部访问dgrid-selectdgrid-deselect事件可以通过其cells属性访问。

来自 mixin 的文档:

选择对象存储一个嵌套散列,其中外部散列由项目 ID 键入,内部散列由列 ID 键入。

dgrid-select 和 dgrid-deselect 事件仍会触发,但包括一个包含单元对象数组的单元格属性,而不是行属性。

于 2016-04-02T11:36:14.323 回答