【问题标题】:Dojo EnhancedGrid and programmatic selectionDojo EnhancedGrid 和程序化选择
【发布时间】:2012-07-03 15:50:05
【问题描述】:

这是我的问题:在我的应用程序中,我有一个 Dojo EnhancedGrid,由 ItemFileReadStore 支持。页面流程如下所示:

  1. 用户从选择列表中选择一个值。
  2. 列表中的项目发布到服务器上,然后使用来自服务器的数据更新网格(不要问为什么,它应该是这样工作的)
  3. 新项目在网格中突出显示。

现在,前两个步骤很有效;然而,第三步让我有些头疼。数据成功 POST 到服务器后(通过 dojo.xhrPost() ),以下代码运行:

myGrid.store.close();
myGrid._refresh();
myGrid.store.fetch({
    onComplete : function(items) {
        for ( var i = 0; i < items.length; i++) {
             if (items[i].documentType[0].id == documentTypeId) {                                               
                 var newItemIndex = myGrid.getItemIndex(items[i]);
                 exportMappingGrid.selection.deselectAll();
                 exportMappingGrid.selection.addToSelection(newItemIndex);
             }
     }
      }
     });

现在,网格的选择已更新(即选择对象的 selectedIndex > 0),但视觉上没有响应,除非我将鼠标悬停在“选定”行上。如果我删除 .deselectAll() 行(我怀疑它是罪魁祸首),那么有时我会一次选择两个项目,尽管网格 selectionMode 属性设置为 single em>。

对这个有什么想法吗?

非常感谢。

【问题讨论】:

    标签: dojo dojox.grid


    【解决方案1】:

    你需要像这样使用setSelected()

    exportMappingGrid.selection.setSelected(newItemIndex, true);
    

    第二个参数为true选择行,false为取消选择。

    【讨论】:

    • 我使用了 setSelected,它似乎工作得很好,直到我遇到了一些麻烦:如果我在网格中选择一行(通过单击鼠标),然后添加另一行并以编程方式选择它我结束最多有两个选定的行。
    • 在类似的情况下,我发现在以编程方式选择新行之前,我必须执行 setSelected(xxx, false) 取消选择旧行。
    【解决方案2】:

    这对我有用:

    grid.selection.clear();
    grid.selection.addToSelection(newItemIndex);
    grid.selection.getFirstSelected();
    

    乔恩

    【讨论】:

    • 但这也有效:grid.selection.clear(); grid.selection.setSelected(newItemIndex, true);
    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多