DGrid - 使用拖放时的单选模式 - >多个选择的结果

时间:2014-04-23 20:24:04

标签: javascript dojo dgrid dojo-dnd

我正在尝试使用以下属性来运行DGrid:

  • 拖放
  • 单一选择

不幸的是,这并不像我希望的那样容易。我正在宣布我的DGrid:

this._grid = new (declare([OnDemandGrid, DijitRegistry, Selection, DnDGrid]))({
    store: this.store,
    columns: [
        {label: "ID", field:"id", sortable: false},
        ...
    ],
    touchesToScroll: 2, // Required to enable d&d on mobile
    dndSourceType: "grid-row",
    getObjectDndType: function(item){
        return [item.type ? item.type : this.dndSourceType];
    },
    selectionMode: "single"
}, this.gridDiv);
this._grid.startup();

在大多数情况下,这很有效。 DnD正在运作。选择主要是工作。偶尔会有一些奇怪的状态。以下是这些案例:


转换选择

如果我执行班次选择,那么我会看到多个项目看起来好像被选中了。他们将附加以下css类:

.claro .dojoDndItemAnchor, .claro .dojoDndItemSelected { ... }

enter image description here

收听dgrid-select事件时,会正确报告所选元素。

尝试拖动所选元素也可正常工作 - >只有其中一个被移动。

编辑: 我找到了 Shift Select 问题的解决方案。 It is posted as answer below。我仍然无法弄清楚下一个问题。


以编程方式取消选择

如果我执行以下操作:

  1. 选择项目
  2. 以编程方式取消选择全部:this._grid.clearSelection();
  3. 以编程方式选择其他项目:this._grid.select(row);
  4. 留下两个看起来被选中的物品。
  5. enter image description here

    这两个项目有不同的风格。不正确的人有:

    .claro .dojoDndItemAnchor, .claro .dojoDndItemSelected { ... }
    

    正确的人有:

    .dgrid-selected
    

    和以前一样,在收听dgrid-select事件时,它会正确报告所选元素。


    这似乎是导致我出现问题的默认dojo DnD模块。看看doc似乎我需要对选择器做一些事情。 Selector有一个名为singular的属性,但我无法弄清楚如何/在何处设置它。

    单数信息:https://dojotoolkit.org/reference-guide/1.9/dojo/dnd.html#id2

2 个答案:

答案 0 :(得分:3)

RE程序化取消选择,我认为你发现了一个合法的dgrid错误。我快速浏览了一下并发出pull request。查看该变更集是否为您解决了问题。

答案 1 :(得分:1)

可以使用dndParams字段阻止转换选择多项选择问题。

像这样实例化网格将解决问题:

this._grid = new (declare([OnDemandGrid, DijitRegistry, Selection, DnDGrid]))({
    store: this.store,
    columns: [
        {label: "ID", field:"id", sortable: false},
        ...
    ],
    touchesToScroll: 2, // Required to enable d&d on mobile
    dndSourceType: "grid-row",
    getObjectDndType: function(item){
        return [item.type ? item.type : this.dndSourceType];
    },
    selectionMode: "single",
    dndParams:{singular: true} // ADDED THIS.
}, this.gridDiv);
this._grid.startup();

仍然没有想出如何应对程序化变化。

相关问题