【问题标题】:Retrieving selected cell information in dgrid (dojo)在 dgrid (dojo) 中检索选定的单元格信息
【发布时间】:2012-04-26 08:17:18
【问题描述】:

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

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

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

【问题讨论】:

    标签: dojo dgrid


    【解决方案1】:

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

    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: {},
    

    【讨论】:

    • 我的问题是关于 dgrid(gridFromHtml)(参考:github.com/SitePen/dgrid)而不是关于 dojox 中的 DataGrid。上述方法不适用于dgrid。
    • 我的错误。我以前没有使用过这些小部件。但是快速查看代码,我更新了我的答案。希望这会有所帮助。
    • 如何选择特定单元格而不是整行?
    【解决方案2】:

    例如,您可以使用网格中的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;
    }
    

    【讨论】:

      【解决方案3】:

      你应该使用CellSelection mixin

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

      来自 mixin 的文档:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-11
        相关资源
        最近更新 更多